我想继承默认 Material 设计风格的所有 Button
样式,并保留按下按钮时出现的背景颜色和阴影(所谓的高度)。我唯一想改变的是波纹效果的颜色(当你触摸按钮然后移动手指时)。
如果我使用以下样式:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">@style/MyTheme.Button</item>
</style>
<style name="MyTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">@drawable/btn_material</item>
</style>
drawable/btn_material 是:
<ripple android:color="#ffff0000">
<item android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
然后我的按钮失去了背景颜色和高度阴影。
有什么方法可以告诉按钮保留从父级继承的默认颜色和阴影,并且仅用给定的颜色替换波纹颜色?本质上,我想实现像 android:backgroundRipple
属性这样的东西,它只会改变波纹,而其他一切都完好无损。
最佳答案
RippleDrawable 波纹= (RippleDrawable)view.getBackground();
int[][] attr= new int[][] { new int[] { android.R.attr.state_enabled} }; int[] 颜色 = new int[] { Color.RED };//将波纹颜色设置为红色
ColorStateList color = new Color(状态, 颜色); 波纹.setColor(颜色);
关于android - 如何更改 Android 按钮波纹颜色,同时保留其他样式属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39412615/