简体   繁体   中英

android sherlock actionbar menu selected item of menu with underline, color change

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

在此处输入图片说明

I would like to change the blue color in eg 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?

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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM