简体   繁体   English

android sherlock actionbar菜单选中的菜单项带有下划线,颜色更改

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

I'm using ActionBarSherlock, I have ActionBar like in picture: 我正在使用ActionBarSherlock,我的ActionBar如图所示:

在此处输入图片说明

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: 我的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). 不确定是否仍然需要帮助,但是要更改操作栏Sherlock(abs)中操作栏上的下划线,您只需要用9色可绘制绘图板替换操作栏的背景,该绘图板具有可拉伸的顶部轮廓和底部的颜色(如果您在Abs示例代码中搜索“ ad_tab_unselected_holo.png”,则可以使用此颜色,只需更改图像中的颜色即可)。

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). 然后,您需要添加此png并更改,将以下内容添加到您的style.xml中(请注意,我们同时更改了android:background和background以便向后兼容)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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