[Android] TabLayoutの背景色を変更する「選択時・非選択時」
目次
TabLayoutの背景色を変更する「選択時・非選択時」
TabLayoutの選択時・非選択時の背景色を変更するには以下の通り
drawableにtab_color_selector.xmlを作成
tab_color_selector.xml
*android:state_selected=”trueがある方が選択時の色
*上記コードでは選択色は白、非選択色は黒となる
layoutに実装
app:tabTextColor=”@color/accent” テキストの色
app:tabSelectedTextColor=”@color/white” 選択時のテキストの色
app:tabTextAppearance=”@style/TabText” テキストのスタイル
app:tabBackground=”@drawable/tab_color_selector” 背景
選択時の画像を変更する場合は
tab_icon_selector_1.xml
Activity
tabLayout.addTab(tabLayout.newTab().setText(R.string.title_tab_1).setIcon(R.drawable.tab_icon_selector_1))