`
jeffrey123
  • 浏览: 24139 次
  • 性别: Icon_minigender_1
  • 来自: 南京
最近访客 更多访客>>
社区版块
存档分类
最新评论

how to change the background of actionbar.tab

 
阅读更多

Step1 : create three background image (a)when tab is selected(b)when tab is in default state(c)when tab is focused.

Step2 : create selector xml under drawable folder.
e.g: actionbar_tabs_state_color.xml
<?xml version="1.0" encoding="utf-8"?>
<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="@drawable/tab_default"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected"/>
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focused"/>
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focused"/>
<!-- Pressed -->
<item android:state_pressed="true" android:drawable="@drawable/tab_focused"/>
</selector>

Step3: create new style element in style.xml

<style name="customActionBarTabStyle">
<item name="android:background">@drawable/actionbar_tabs_state_color</item>
<item name="android:paddingLeft">14dp</item>
<item name="android:paddingRight">14dp</item>

</style>

Step4 : create new style element in style.xml to set “customActionBarTabStyle” style.

<style name="CustomActionBar" parent="android:style/Theme.Holo">

<item name="android:actionBarTabStyle">@style/customActionBarTabStyle</item>


</style>

Step5: Use style element created in step4 in your activity attribute in AndroidManifest.xml

    case 1: just for one activity
<activity android:name=".base.activity.MyActivity"
android:screenOrientation="sensorLandscape" android:theme="@style/CustomActionBar">
</activity>

case 2: all the activity

<application  android:theme="@style/AppTheme"> </application>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics