忘備録に。
selectorの設定というと、viewのlayoutのxmlの中でbackgroundに指定する方法がよく出てくるが、textColorにも設定できる。
backgroundに設定するかtextColorに設定するかでselectorのcolorの指定の仕方が違うので注意する。
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_initial_footer_button"/>
これがbackgroundに設定するパターン
backgroundに設定したselectorは
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<color android:color="@color/white"/>
</item>
<item android:state_checked="false">
<color android:color="@color/black"/>
</item>
</selector>
このcolorはbackgroundの色が変わる
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/selector_initial_footer_button"/>
これがtextColorに設定するパターン
textColorに設定したselectorは
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/white"/>
<item android:state_checked="false" android:color="@color/black"/>
</selector>
colorの属性は補完で出てこないのは何故なんだろう・・・。
これで文字色が変わる
一つのbackgroundに設定したdrawableでtextColorも一緒に設定できたら便利だなぁ…。