XML : android:popupBackground not working for context menus

Why does my styles.xml code successfully change the background colour of my actionbar overflow menu, but fail to change the background colour of the context menu in my app?

  <style name="AppBaseTheme" parent="Theme.AppCompat.Light">      <!--<item name="android:actionBarStyle">@style/DarkActionBar</item> -->    </style>    <!-- Application theme. -->  <style name="AppTheme" parent="AppBaseTheme">        <!-- All customizations that are NOT specific to a particular API-level can go here. -->      <item name="android:popupMenuStyle">@style/MyPopupMenu</item>      <item name="android:itemTextAppearance">@style/MyCustomMenuTextAppearance</item>    </style>    <!-- Popup Menu Background Color styles -->  <!-- <style name="MyPopupMenu"  parent="@android:style/Widget.Holo.ListPopupWindow"> -->  <!-- <style name="MyPopupMenu"  parent="@android:style/Widget.PopupMenu"> -->  <style name="MyPopupMenu"  parent="@style/Widget.AppCompat.PopupMenu">      <item name="android:popupBackground">@color/dark_gray</item>   </style>  <!-- Popup Menu Text Color styles -->  <style name="MyCustomMenuTextAppearance">      <item name="android:textColor">@color/white</item>  </style>    

I've been stuck on this for a couple of hours and none of the solutions on SO for similar questions have worked for me.

If it helps, here is my Java code where the context menu is created:

  @Override  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {      super.onCreateContextMenu(menu, v, menuInfo);        AdapterView.AdapterContextMenuInfo info =              (AdapterView.AdapterContextMenuInfo) menuInfo;      String selectedWord = ((TextView) info.targetView).getText().toString();      menu.setHeaderTitle(selectedWord);        MenuInflater inflater = getActivity().getMenuInflater();      inflater.inflate(R.menu.shopping_list_name_context, menu);  }    

And, for completeness, here is my context menu xml, shopping_list_name_context.xml:

  <item android:id="@+id/rename_shopping_list"        android:icon="@drawable/ic_action_edit"        android:title="@string/rename_shopping_list" />    <item android:id="@+id/empty_shopping_list"        android:icon="@drawable/ic_action_discard"        android:title="@string/empty_shopping_list" />    <item android:id="@+id/delete_shopping_list"        android:icon="@drawable/ic_action_discard"        android:title="@string/delete_shopping_list" />    

No comments:

Post a Comment