I am trying to change the icon icon color in FAB based on the state of the button:
<android.support.design.widget.FloatingActionButton android:id="@+id/search_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="16dp" android:tint="@color/add_button_tint" android:src="@drawable/ic_add_black_24dp" />
add_button_tint.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/white" /> <item android:color="@color/black"/> </selector>
This works fine in API> 23, however in older versions of android it throws an exception.
This is where I got confused:
The android: tint property lives in FAB support and works if its just color, even in older versions of android. IE this works in all versions I tested:
android:tint="@color/black
But when I use the selector, it is not. What am I doing wrong? Is it possible to change the color of the icon based on state for FAB in older versions of Android?
android material-design android-styles floating-action-button
lostintranslation
source share