How to customize ActionBar in Android (ActionbarSh

2019-04-16 09:27发布

I have used ActionBarSherlock in my application for providing ActionBars to pre honeycomb devices. I want to use Light.DarkActionBar Theme in, How can I customize following for parts of the ActionBar (see image)

  1. Background color of ActionBar
  2. Background Image for ActionBar tab bar
  3. The bottom line which represents the selected tab
  4. The divider between tabs...

enter image description here

I have tried using following settings, Though I have achieved some success but the result however doesn't look as expected,

<item name="android:background">@drawable/bg_title_bar</item>
<item name="background">@drawable/bg_title_bar</item>
<item name="actionModeSplitBackground">@drawable/bg_tab_bar</item>
<item name="android:actionModeSplitBackground">@drawable/bg_tab_bar</item>

Which are the other settings that I should use ? Thanks!!

2条回答
forever°为你锁心
2楼-- · 2019-04-16 09:37

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

查看更多
\"骚年 ilove
3楼-- · 2019-04-16 09:49

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>
查看更多
登录 后发表回答