0

將這一段代碼添加到我的styles.xml文件中,將按鈕的主要顏色更改爲colorPrimary的綠色。更改按鈕帶紋波的背景顏色

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button"> 
    <item name="colorButtonNormal">@color/colorPrimary</item> 
</style> 

</resources> 

然後我試圖與它的連鎖反應結合,因爲我在你需要創建一個XML ripple_effect文件,並使用它作爲背景的按鈕,另一疊後閱讀。然後將按鈕的樣式設置爲style.xml中詳細描述的自定義樣式。

我如何鏈接到按鈕編輯器

enter image description here

我在做什麼錯。是否有一種更簡單的方法來實現在按鈕和顏色上添加漣漪效果。我一直試圖解決這個堆棧溢出帖子,但每個解決方案似乎不同。我對API 23

回答

0

您可以使用setColorFilter():

btn.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); 
0

可以使用ThemeOverlay s內完成。

res/values/themes.xml有了這個:

<style name="GreenButtonTheme" parent="ThemeOverlay.AppCompat.Light"> 
    <item name="colorButtonNormal">@color/green</item> 
</style> 

而在你的xml:

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:theme="@style/GreenButtonTheme" /> 

然後你會得到這樣的輸出:

enter image description here

更多見this article細節。