2015-05-12 30 views
0

我想知道如何更改制表符颜色。我试过多个代码但没有工作,所以请帮助我如何更改默认颜色?下面的代码我使用:ActionBar制表符颜色

actionBar.setStackedBackgroundDrawable(getResources() 
         .getDrawable(R.drawable.tab_selector)); 

tab_selector.xml

- > - > - >

<!-- Focused states --> 
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/cab_background_top_example" /> 
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/cab_background_top_example" /> 

<!-- Pressed --> 
<item android:state_selected="true" android:state_pressed="true" android:drawable="@color/tabcolor" /> 
<item android:state_pressed="true" android:drawable="@color/tabcolor" /> 

+0

检查答案在这里:http://stackoverflow.com/a/16140075 –

回答

0
+0

我有下载自定义的操作栏,但仍然无法正常工作。我是否需要使用我下载的样式? –

+0

查看关于如何使用操作栏样式生成器http://java.dzone.com/articles/creating-custom-android-styles同样将生成的文件夹相应地粘贴到您的项目中 – Ted

0

使用样式也可以做到这一点(代码是基于支持-V7库)

<style name="MyAppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 

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

    </style> 

    <style name="MyActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView"> 

     <item name="android:background">@drawable/tab_selector</item> 
     <item name="background">@drawable/tab_selector</item> 

    </style> 

欲了解更多信息请访问Official Doc : Styling the Action Bar

Happy_Coding ... :)