例えば以下のような drawable を用意して Checkbox の android:button に指定したのが次のスクリーンショットの下2つです。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp">
<selector>
<item android:state_checked="true">
<shape android:shape="oval">
<size
android:width="18dp"
android:height="18dp" />
<stroke
android:width="6dp"
android:color="#6666ff" />
</shape>
</item>
<item>
<shape android:shape="oval">
<size
android:width="18dp"
android:height="18dp" />
<stroke
android:width="2dp"
android:color="#cccccc" />
</shape>
</item>
</selector>
</item>
</layer-list>
<CheckBox
...
android:button="@drawable/checkbox"
... />

全く同じコードで Activity の theme を Material Design Components for Android 1.0.0 に変えたのが次のスクリーンショットです。

同じようになってますね。
全く同じコードで Activity の theme を Material Design Components for Android 1.1.0 に変えたのが次のスクリーンショットです。

なんということでしょう!android:button で指定した drawable resource が Material Design の theme color で tint されるようになりました。tint で使われる色は colorControlActivated と colorOnSurface です。
この挙動を止めるには app:useMaterialThemeColors="false" を指定します。
<CheckBox
...
android:button="@drawable/checkbox"
app:useMaterialThemeColors="false"
... />

tint されなくなりました!
0 件のコメント:
コメントを投稿