【问题标题】:Android : Change theme background of Popup menuAndroid:更改弹出菜单的主题背景
【发布时间】:2014-09-06 16:43:03
【问题描述】:

当我单击操作栏中的某个项目时,我的弹出菜单具有黑色背景主题颜色。我想将弹出菜单的主题更改为全息光(白色)。

我该怎么做?

这是我的 style.xml 文件,暂时为空:

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.



    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.



        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">

        <!-- All customizations that are NOT specific to a particular API-level can go here. -->

    </style>

</resources>

以及清单摘录:

<application
        android:name="com.app.ccccccc.activities.cccccccc"
        android:hardwareAccelerated="true"
        android:allowBackup="true"
        android:icon="@drawable/ic_action_blob"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

【问题讨论】:

    标签: android android-theme android-menu


    【解决方案1】:

    在操作菜单的 onClick 上,您可以通过编程方式编写设置背景颜色的代码。

    或使用,

    <style name="AppTheme" parent="android:Theme.Light">
        <item name="android:popupMenuStyle">@style/PopupMenu</item>
    </style>
    
    <style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
        <item name="android:popupBackground">@android:color/white</item>
    </style>
    
    manifest.xml:
    
     <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    .............
    </application>
    

    【讨论】:

    • 谢谢。你能告诉我必须在我的 style.xml 文件中添加
    • 但是我的 style.xml 文件在哪里?*
    • 不要删除您在 Style.xml 中的内容
    • 嘿伙计,你知道 'android:popupBackground' 对 api
    【解决方案2】:

    尝试如下编辑您的styles.xml

    在您的基本主题中:

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        ...
        <item name="android:popupMenuStyle">@style/PopupMenuStyle</item>
    </style>
    

    然后像这样定义PopupMenuStyle

    <style name="PopupMenuStyle" parent="android:Widget.Holo.Light.PopupMenu">
        <item name="android:popupBackground">@android:color/white</item>
    </style>
    

    请注意,默认弹出菜单样式不会像我在上面所做的那样将背景设置为纯色,而是使用具有 9-patch 背景的可绘制状态列表来提供阴影等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 2016-03-16
      • 2021-09-27
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多