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细节。