In the project, I used to change the background image and background color of the custom androidmenu. I posted an article on the Internet as follows: This article is reprinted from the elephant in the pond.
After the background color is changed, the effect is as follows:
DetailsCodeAs follows:
Public Boolean oncreateoptionsmenu (menu) {// menuinflater mmenuinf = getmenuinflater (); // mmenuinf. inflate (R. menu. main_menu, menu); menu. add (0, R. id. main_menu_about, 0, R. string. main_menu_about ). seticon (R. drawable. menu_icon_about); menu. add (0, R. id. main_menu_exit, 1, R. string. main_menu_exit ). seticon (R. drawable. menu_icon_exit); setmenubackgroudcolor (); Return true ;}
Public Boolean onoptionsitemselected (menuitem item) {Switch (item. getitemid () {case R. id. main_menu_about: break; case R. id. main_menu_exit: // exit the system // cancel the notification // icationicationmanager. cancel (R. drawable. logo_icon_16); dialogutil. exitdialog (myhomeactivity. this, icationicationmanager); break;} return true ;}
You can change the color as follows:
Private void setmenubackgroudcolor () {getlayoutinflater (). setfactory (New Factory () {public view oncreateview (string name, context, attributeset attrs) {If (name. equalsignorecase ("com. android. internal. view. menu. iconmenuitemview ") | Name. equalsignorecase ("com. android. internal. view. menu. listmenuitemview ") {try {layoutinflater F = getlayoutinflater (); final view = f. createview (name, null, attrs); new handler (). post (New runnable () {public void run () {// view. setbackgroundresource (R. drawable. menu_backg); // sets the background image view. setbackgroundcolor (color. parsecolor ("# f6f9fe"); // sets the background color});} catch (inflateexception e) {e. printstacktrace ();} catch (classnotfoundexception e) {e. printstacktrace () ;}} return NULL ;}});}
that's it... But I did not test it! I think it should be feasible!