着色按钮在Android中使用的材料设计与AppCompat [英] Coloring Buttons in Android with Material Design and AppCompat

查看:107
本文介绍了着色按钮在Android中使用的材料设计与AppCompat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在该 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:

<一个href="https://$c$c.google.com/p/android/issues/detail?id=78428">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>

这篇关于着色按钮在Android中使用的材料设计与AppCompat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆