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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值