This is what you need to do:
Create a style for your application: Here I customize the tab bar and text (I use a basic compatibility theme, but you can use HOLO or whatever):
<style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="android:actionBarTabTextStyle">@style/TabTextStyle</item> <item name="android:actionBarTabStyle">@style/TabBarStyle</item> <item name="actionBarTabTextStyle">@style/TabTextStyle</item> <item name="actionBarTabStyle">@style/TabBarStyle</item> </style>
Create these styles:
<style name="TabTextStyle" parent="@style/Widget.AppCompat.ActionBar.TabText"> <item name="android:textColor">@color/ab_tab_txt</item> </style> <style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView"> <item name="android:background">@drawable/tab_indicator</item> </style>
For color and pictures, you can create a selector that allows you to change the tab based on clicks and selections:
File: res / color / ab_tab_txt (I use the color file from res / values ββto set my constants, but you can put it like this: #FFF)
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/ab_tab_txt_selected"/> <item android:color="@color/ab_tab_txt_unselected"/> </selector>
Res / drawable / tab_indicator file
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_example" /> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_example" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_example" /> <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" /> <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" /> </selector>
My available files are NinePatches, which I create with this useful tool: http://jgilfelt.imtqy.com/android-actionbarstylegenerator/
Cristianguerrero
source share