Coloring Buttons in Android with Material Design and AppCompat Ask Question

Coloring Buttons in Android with Material Design and AppCompat Ask Question

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:

望ましい結果を示す画像

白いボタンがデフォルトですが、私が欲しいのは赤いボタンです。

以前、ボタンの色を変更するために次の操作を行っていましたstyles.xml

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

動的に実行するには:

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

また、テーマの親をからに変更しまし@android:style/Theme.Material.Light.DarkActionBarTheme.AppCompat.Light.DarkActionBar

ベストアンサー1

サポート ライブラリ rev.22 (2015 年 3 月 13 日金曜日) で正式に修正されました。関連する Google コードの問題を参照してください。

https://issuetracker.google.com/issues/37008632

使用例

テーマ.xml:

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

v21/テーマ.xml

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

おすすめ記事