前提・実現したいこと
Buttonのbackgroundについて、Android5.1.1と8では適用されるがAndroid4.4.4では適用されない。
テーマのスタイルではなく、個別のレイアウトでボタンに直接指定すれば問題ないが、Android4.4.4のみ、テーマのスタイルで指定できない。
Android4.4.4でもテーマのスタイルで指定したい。
※ボタン毎に個別指定だとソースが煩雑になるため。
該当のソースコード
styles.xml
xml
1 <!-- Base application theme. --> 2 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 3 <!-- Customize your theme here. --> 4 <item name="android:buttonStyle">@style/CustomButton</item> 5 </style> 6 <style name="CustomButton" parent="@android:style/Widget.Button"> 7 <item name="android:textColor">@color/font_color</item> 8 <item name="android:background">@drawable/button_custom</item> 9 </style>
button_custom.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2 3<selector 4 xmlns:android="http://schemas.android.com/apk/res/android"> 5 <!-- ボタンが押されてないときの定義 --> 6 <item android:state_pressed="false" > 7 <shape xmlns:android="http://schemas.android.com/apk/res/android" 8 android:shape="rectangle"> 9 <solid android:color="@color/colorAccent"/> 10 <corners android:radius="5dp" /> 11 </shape> 12 </item> 13 <!-- ボタンが押されたときの定義 --> 14 <item android:state_pressed="true" > 15 <shape xmlns:android="http://schemas.android.com/apk/res/android" 16 android:shape="rectangle"> 17 <solid android:color="@color/button_prs_color"/> 18 <corners android:radius="5dp" /> 19 </shape> 20 </item> 21</selector>
補足情報(FW/ツールのバージョンなど)
Android Studio3.4
API14から28対象でターゲットは28
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/18 14:08