着色按钮在Android中使用的材料设计与AppCompat按钮、材料、Android、AppCompat

由网友(词不达意)分享简介:在该 AppCompat 更新今天就出来了,我能够改变在Android的大号按钮的颜色,但不是在旧版本。包括新AppCompat更新后我无法改变颜色的任一版本,当我尝试按钮即可消失。有谁知道如何更改按钮的颜色?Before the AppCompat update came out today I was able...

在该 AppCompat 更新今天就出来了,我能够改变在Android的大号按钮的颜色,但不是在旧版本。包括新AppCompat更新后我无法改变颜色的任一版本,当我尝试按钮即可消失。有谁知道如何更改按钮的颜色?

Before the AppCompat update came out today I was able to change the color of buttons in Android L but not on older versions. After including the new AppCompat update I am unable to change the color for either version, when I do try the button just disappears. Does anyone know how to change the button color?

下面的图片显示了我想要实现:

The following pictures shows what I want to achieve:

白色按钮是默认的,红色的是我想要的。

The white button is default, the red one is what I want.

这是我在做什么previously改变按钮的颜色 styles.xml

This is what I was doing previously to change the color of the buttons in the styles.xml:

<item name="android:colorButtonNormal">insert color here</item>

和动态做到这一点:

button.getBackground().setColorFilter(getResources().getColor(insert color here), PorterDuff.Mode.MULTIPLY);

另外,我也从更改主题父@android:款式/ Theme.Material.Light.DarkActionBar Theme.AppCompat.Light.DarkActionBar

推荐答案

正式固定在支持库rev.22(星期五2015年3月13日)。请参阅相关的谷歌code问题:

Officially fixed in Support Library rev.22 (Fri March 13, 2015). See relevant google code issue:

https://$c$c.google.com/p/android/issues/detail?id=78428

使用实例

theme.xml:

theme.xml:

<item name="colorButtonNormal">@color/button_color</item>

V21 / theme.xml

v21/theme.xml

<item name="android:colorButtonNormal">@color/button_color</item>
阅读全文

相关推荐

最新文章