android - 如何更改 Android 2.3 的选项菜单背景?

标签 android menu background

我有相同的标准选项菜单,但我想将项目的背景从白色更改为黑色。我看过很多关于如何执行此操作的帖子,但这些帖子不适用于 2.3。

有谁知 Prop 有与 2.3 版兼容的自定义颜色背景的工作菜单充气器?

最佳答案

查看以下解决方案是否解决了您的问题....

AndroidMenifest.xml

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

menu/options.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/option_1" android:title="Android"/>
    <item android:id="@+id/option_2" android:title="iPhone"/>
    <item android:id="@+id/option_3" android:title="iPad"/>
</menu>

styles.xml

<resources>
    <style name="CustomTheme" parent="android:Theme">
        <!-- Panel attributes -->
        <!-- <item name="android:panelBackground">@drawable/menu_bg</item> -->
        <item name="android:panelFullBackground">@drawable/menu_full_bg</item> 
            <!--    <item name="android:panelColorBackground">#FF0000</item> -->
    </style>

    <!-- <drawable name="menu_bg">#DDDAAA</drawable> -->
    <drawable name="menu_full_bg">#000FFF</drawable>

</resources>

StackoverflowActivity.java

public class StackoverflowActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.options, menu);
        return true;
    }

}

Output

关于android - 如何更改 Android 2.3 的选项菜单背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10394016/

相关文章:

java - 如何从 Android 应用程序发送 ESC 命令?

android - App Auth 库 Android 在请求 token 时抛出 "File not found exception"

java - 为什么我的启动画面不起作用?

Android TextView 未在 ImageView 下方对齐

html - 移动响应菜单 - 子菜单不起作用

android - 如何完成后台播放录音的任务并处理不同的 Activity ?

jquery - 单击同一按钮的动画菜单

javascript - bootstrap-通过代码关闭“移动(汉堡)”菜单

swift - 如何创建跟随 SWIFT 字符的背景?

ios - 当应用程序后台运行时,NSTimer 是否会触发?