2

I'm using ActionBarSherlock, I have ActionBar like in picture:

enter image description here

I would like to change the blue color in e.g. green and I would like to have the selected item of menu with underline (so as in the picture).

My main_menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/item0"
    android:showAsAction="always"
    android:title="@string/menu_item0">
</item>
<item
    android:id="@+id/item1"
    android:showAsAction="always"
    android:title="@string/menu_item1">
</item>
<item
    android:id="@+id/item2"
    android:showAsAction="always"
    android:title="@string/menu_item2">
</item>
<item
    android:id="@+id/action_overflow"
    android:icon="@drawable/ic_action_overflow"
    android:showAsAction="always">
    <menu>
        <item android:id="@+id/contact" android:title="@string/submenu_0"/>
        <item android:id="@+id/info" android:title="@string/submenu_1"/>
        <item android:id="@+id/exit" android:title="@string/submenu_2"/>
    </menu>
</item>
</menu>

How can I do it? In which file?

tshepang
  • 12,111
  • 21
  • 91
  • 136
hipek
  • 201
  • 1
  • 3
  • 15
  • This answers your first question: [Actionbarsherlock - change actionbar line colour](http://stackoverflow.com/q/10044303/1267661) – Sam Dec 16 '12 at 21:47
  • @Sam: That answer relates to something different. It's not any help in this case. – Tomik Dec 16 '12 at 22:35
  • You might find an answer in [Change Action Bar onPressed color](http://stackoverflow.com/a/13847934/244647). Though there other ways to get the desired outcome. – Tomik Dec 16 '12 at 22:41
  • @Tomik hi Tomik, i just started with the customizing my ActionBar. You have wrote in [Change Action Bar onPressed color](http://stackoverflow.com/questions/13845549/change-action-bar-onpressed-color/13847934#13847934), drawable/my_background.xml -> my_background.xml should i place in my projects? I have only: drawable-hdpi/ldpi/mdpi/xdpi, should i create new folder: drawable and there set my_background.xml? – hipek Dec 18 '12 at 15:25
  • Yes, you typically create `drawable` directory where xmls of drawables are placed (e.g. selectors, shape drawables, ...). These xml drawables are density independent. – Tomik Dec 18 '12 at 15:54
  • @Tomik hi Tomik, I decided that I want to use the standard blue underline selected item in ActionBarSherlock (not green as on the photo). I would like to use Theme.Sherlock.Light.DarkActionBar or Theme.Sherlock.Light. Can you tell me, what should i write in my style.xml? currently, when i click on the menu, this is the entire area in underlined in blue and disappears when you release the button(selectet item of menu). I would like to have: i click the item on menu: is underline as in the picture (on blue) and when i release the button, the undeline have left – hipek Dec 19 '12 at 00:33

1 Answers1

0

Not sure if you still need help with this but to change the underline on the action bar in action bar sherlock (abs) you just need to replace the background of the action bar with a 9-patch drawable that has a stretachable top seciton and a colour at the bottom (if you search for 'ad_tab_unselected_holo.png' in the abs sample code you can use this and just change the colour in the image).

You then need to att this png and change add the following to your style.xml (note we are changing both android:background & background for backwards compatability).

<style name="CustomTheme" parent="Theme.Sherlock">    
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
    <item name="android:background">@drawable/ad_tab_unselected_holo</item>
    <item name="background">@drawable/ad_tab_unselected_holo</item>
</style>

Then just apply this style in the manifest to your activity as follows;

<activity
   android:label="@string/an_activity"
   android:name="com.sample.TestActivity"            
   android:theme="@style/CustomTheme"/>
Andy B
  • 753
  • 5
  • 12