【问题标题】:support actionbar menu styling支持操作栏菜单样式
【发布时间】:2015-02-05 12:26:56
【问题描述】:

如何设置 Android ActionBar 溢出菜单的样式(背景颜色、文本颜色、自定义可绘制对象等)?

我一直在尝试使用以下样式来执行此操作,但似乎没有任何效果。任何帮助将不胜感激。

<resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="android:actionBarWidgetTheme">@style/MyActionBar</item>
            <item name="android:actionBarStyle">@style/MyActionBar</item>
        </style>

        <style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
            <item name="android:textColor">@android:color/holo_blue_light</item>
            <item name="android:actionBarItemBackground">@android:color/holo_green_light</item>
            <item name="android:actionMenuTextColor">@android:color/holo_green_dark</item>
        </style>
    </resources>

TIA!

BTW minSdk 设置为 14

AndroidManifest 是

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app1.app1">

    <application android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

【问题讨论】:

    标签: android android-styles android-actionbar-compat


    【解决方案1】:

    您是否在 AndroidManifest.xml 文件中调用它? 我的 style.xml 中的示例

    <resources xmlns:android="http://schemas.android.com/apk/res/android">
    
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>
    
    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/green_dark</item>
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    </style>
    
    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/white</item>
        <item name="android:textStyle">bold</item>
    </style>
    

    在清单文件中

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher1"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme" >
        <activity.....
    

    为了实现点击监听,你需要为这种情况创建选项菜单。

    【讨论】:

    • 是的,它是在我的清单应用程序主题中设置的,但奇怪的是似乎没有任何效果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多