自定义主题ActionBar android(菜单不起作用)

时间:2013-10-07 16:28:54

标签: android android-actionbar android-theme android-menu

我想自定义我的应用并且我已经应用了主题,但选项菜单似乎不适用我的主题。

我希望我的文字颜色为白色,背景为黑色,突出显示/选中的菜单项为黄色。 这是我的theme.xml:

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="android:actionMenuTextColor">@color/application_color5</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>
    <item name="android:selectableItemBackground">@drawable/icone_barratopo_selector</item>
    <item name="android:actionBarItemBackground">@drawable/icone_barratopo_selector</item>
    <item name="android:selectableItemBackground">@drawable/icone_barratopo_selector</item>
    <!-- Panel attributes -->
    <!-- <item name="android:panelBackground">@drawable/selectable_background</item> --


    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="actionMenuTextColor">@color/application_color5</item>
    <item name="actionBarTabStyle">@style/MyActionBarTabs</item>
    <item name="selectableItemBackground">@drawable/icone_barratopo_selector</item>
    <item name="actionBarItemBackground">@drawable/icone_barratopo_selector</item>
    <item name="selectableItemBackground">@drawable/icone_barratopo_selector</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/background_barratopo_superior</item>
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/background_barratopo_superior</item>
    <item name="titleTextStyle">@style/MyActionBarTitleText</item>
</style>

<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/application_color2</item>
</style>

<!-- ActionBar tabs text -->
<style name="MyActionBarTabText" parent="@style/Widget.AppCompat.ActionBar.TabText">
    <item name="android:textColor">@drawable/tab_text_selector</item>
</style>

<!-- ActionBar tabs styles -->
<style name="MyActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView">

    <!-- tab indicator -->
    <item name="android:background">@drawable/actionbar_tab_indicator</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_tab_indicator</item>
</style>

我的menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motobox="http://schemas.android.com/apk/res-auto" >

<!--
      <item
    android:id="@+id/option_availability"
    android:icon="@drawable/icone_barratopo_mymotobox"
    android:orderInCategory="100"
    motobox:showAsAction="always"/>
-->
<item
    android:id="@+id/option_refresh"
    android:icon="@drawable/icone_barratopo_back"
    android:orderInCategory="100"
    motobox:showAsAction="always"/>
<item
    android:id="@+id/status"
    android:orderInCategory="100"
    android:title="Indisponível"
    motobox:showAsAction="never"/>
<item
    android:id="@+id/logout"
    android:orderInCategory="100"
    android:title="Logout"
    motobox:showAsAction="never"/>

和我的selector.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/application_color3" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>

<!-- Pressed -->
<item android:drawable="@color/application_color2" android:state_pressed="true"/>

<!-- Focused -->
<item android:drawable="@color/application_color2" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/>

2 个答案:

答案 0 :(得分:0)

将文件从theme.xml重命名为

res/values/themes.xml

请记住,您可以将主题应用到整个应用

<application android:theme="@style/myCustomTheme">

或个人活动

<activity android:theme="@android:style/myCustomTheme">

答案 1 :(得分:0)

编辑专栏:

<item name="background">@drawable/actionbar_tab_indicator</item>

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

:)