具有不同颜色的标准Android按钮我想稍微改变一个标准的Android按钮的颜色,以便更好地匹配客户的品牌。到目前为止,我发现最好的方法是更改Button可拉到位于res/drawable/red_button.xml:<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/red_button_pressed" />
<item android:state_focused="true" android:drawable="@drawable/red_button_focus" />
<item android:drawable="@drawable/red_button_rest" /></selector>但要做到这一点,我实际上需要为每个要自定义的按钮创建三个不同的绘图(一个用于REST按钮,一个用于聚焦时,另一个用于按下)。比我需要的要复杂得多,也不干燥。我真正想做的就是把某种颜色转换到按钮上。有比我更容易改变按钮颜色的方法吗?
3 回答
![?](http://img1.sycdn.imooc.com/545864490001b5bd02200220-100-100.jpg)
米脂
TA贡献1836条经验 获得超3个赞
button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
button.getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
- 3 回答
- 0 关注
- 327 浏览
添加回答
举报
0/150
提交
取消