Sorry if this question have been asked before.
I want to change icon when it is selected in tab of tab layout. How can I do this using selector?.
I have two tabs in my application on selected state icon should change.
1. create a custom tab selector- You need to add both state selected true and false
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/home_fill"
android:state_selected="true"/>
<item android:drawable="@drawable/home_line"
android:state_selected="false"/>
</selector>
2. Add the custom tab selector drawable as the icon for tabItem
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/footer"
app:tabIndicatorColor="@color/female_colour">
<android.support.design.widget.TabItem
android:id="@+id/tab_home"
android:layout_width="@dimen/_25dp"
android:layout_height="@dimen/_25dp"
android:padding="@dimen/_4dp"
android:icon="@drawable/tab_home"
/>
</android.support.design.widget.TabLayout>
Code is Tested on Android version 7.1.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With