How to customize ActionBar in Android (ActionbarSherlock)?

主宰稳场 提交于 2019-12-04 19:46:16

This is how I did it just in case someone has similar requirements in future..

I downloaded a sample zip file from Style Genarator... Unzipping and a close look on the content suggested that I needed following attributes,

  1. for Background color of ActionBar

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

2. for Background Image for ActionBar tab bar

    <item name="backgroundStacked">@drawable/tab_bg</item>
    <item name="android:backgroundStacked">@drawable/tab_bg</item>  

3. for The bottom line which represents the selected tab

               i. I created a style as follows
                    <style name="ActionBar.TabStyle" parent="@style/Widget.Sherlock.Light.ActionBar.TabView">
                    <item name="background">@drawable/ab_tab_indicator</item>
                    <item name="android:background">@drawable/ab_tab_indicator</item>
                </style>
               ii. I used that style in the theme as follows
                 <item name="actionBarTabStyle">@style/ActionBar.TabStyle</item>
                 <item name="android:actionBarTabStyle">@style/ActionBar.TabStyle</item>

4 for The divider between tabs...

in theme I added two lines..

  <item name="actionBarTabBarStyle">@style/My.ActionBar.TabBar</item>
  <item name="android:actionBarTabBarStyle">@style/My.ActionBar.TabBar</item>

than

<style name="My.ActionBar.TabBar" parent="@android:style/Widget.Holo.ActionBar.TabBar">
    <item name="divider">@drawable/tab_divider</item>
    <item name="android:showDividers">middle</item>
    <item name="android:divider">@drawable/tab_divider</item>
    <item name="android:dividerHeight">24dp</item>
    <item name="android:dividerPadding">8dp</item>
    <!-- <item name="android:background">@drawable/tab_unselected</item> -->
</style>

Here is a link! use this style generator, customize as you need. Download the file, copy past all the drawables to respective directories, copy style.xml under values directory.. and use the give theme name as your theme either in manifest of respective activity..

Hope this works for you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!