How can I change the Options menu background for Android 2.3?

user868935 picture user868935 · May 1, 2012 · Viewed 20.3k times · Source

I have the same standard options menu, but I want to change the background of the items from white to black. I've seen many postings about how to do it, but those don't work for 2.3.

Does anyone know of a working menu inflater with a custom-colored background compatible with version 2.3?

**ATTENTION** NO IMAGE PLACEMENT!!! NO CODE FROM OTHER POSTINGS, BECAUSE IVE TRIED THEM ALL HERE!!!

Answer

dira picture dira · May 11, 2012

See if following solution solves your problem....

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