Customizing Background and Text color in Options Menu Android


Options menu in android applications can be customized to set the background or change the text appearance. The background and text color in the menu couldn’t be changed using themes and styles. The android source code (data\res\layout\icon_menu_item_layout.xml)uses a custom item of class “”View for the menu layout. We can make changes in the above class to customize the menu. To achieve the same, use LayoutInflater factory class and set the background and text color for the view.

public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(, menu);

getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context,
AttributeSet attrs) {

if (name .equalsIgnoreCase(“”)) {
try {
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null, attrs);

new Handler().post(new Runnable() {
public void run() {

// set the background drawable
view .setBackgroundResource(R.drawable.my_ac_menu_background);

// set the text color
((TextView) view).setTextColor(Color.WHITE);
return view;
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
return null;
return super.onCreateOptionsMenu(menu);

Google Certified Agency

about the author


  • Great post, Thanks for sharing the code for Customizing Background and Text color in Options Menu.

  • jetti Madhu

    Thanks for posting the menu Item concept.

    final View view = f.createView(name, null, attrs);
    When I declare the view as global instead of local, I able to apply the resource to the last Item of the menu.Not applying to all the menu items.
    Is any thing wrong with me?

  • bo

    Didn’t work for me. Always end up with java.lang.IllegalStateException: A factory has already been set on this LayoutInflater

  • Ali

    It doesn’t work… Always end with exception…

  • udit

    doesn’t work

  • Andrew

    I don’t know why people keep referencing this article, its clearly not working and leaves far to many unanswered questions.

  • sanjeet ajnabee

    hey, it doesn’t change the inflater menu background , only changes the items background.

  • Jyothi

    instead of LayoutInflater f = getLayoutInflater(); use LayoutInflater li = LayoutInflater.from(context); It will work perfect.

  • I want to show my appreciation for your generosity supporting persons that actually need help with the theme. Your special commitment to passing the message up and down came to be extremely significant and has in most cases empowered many people like me to arrive at their targets. Your entire helpful suggestions signifies much a person like me and additionally to my colleagues. Best wishes; from everyone of us.

  • It is the best time to make some plans for the future and it’s time to be happy. I have read this post and if I could I wish to suggest you some interesting things or tips. Maybe you can write next articles referring to this article. I want to read even more things about it!

  • I’m extremely impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one today..

  • I want to express appreciation to this writer for bailing me out of this predicament. Because of looking through the the web and getting techniques that were not beneficial, I thought my life was well over. Existing without the presence of answers to the issues you have fixed by means of this blog post is a crucial case, and the kind which could have badly affected my career if I had not come across your website. Your personal ability and kindness in playing with the whole lot was precious. I am not sure what I would’ve done if I hadn’t discovered such a step like this. It’s possible to at this time look forward to my future. Thanks so much for this high quality and effective help. I won’t be reluctant to recommend your web sites to any person who should have care about this situation.

  • I’m not sure where you are getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for excellent info I was looking for this info for my mission.

  • hey there and thank you for your info – I’ve certainly picked up something new from right here. I did however expertise several technical points using this site, since I experienced to reload the web site lots of times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect your placement in google and can damage your high-quality score if ads and marketing with Adwords. Anyway I am adding this RSS to my email and could look out for a lot more of your respective interesting content. Make sure you update this again soon..

  • I wanted to compose a brief word to be able to express gratitude to you for these marvelous points you are sharing here. My long internet lookup has finally been rewarded with incredibly good insight to share with my co-workers. I ‘d admit that most of us site visitors actually are very much blessed to be in a fantastic community with so many brilliant people with very helpful solutions. I feel pretty happy to have encountered the web page and look forward to many more thrilling moments reading here. Thank you once again for all the details.

  • I’m extremely impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the excellent quality writing, it’s rare to see a nice blog like this one nowadays..

  • CV

    I and my guys came checking out the good hints on the blog while at once I got a horrible suspicion I had not thanked you for them. All of the young boys are already thrilled to read through all of them and have now undoubtedly been taking pleasure in these things. Thanks for truly being considerably kind and for figuring out variety of brilliant issues millions of individuals are really eager to be informed on. My honest regret for not saying thanks to earlier.

  • Hi there, You have done a fantastic job. I will certainly digg it and personally recommend to my friends. I’m confident they will be benefited from this website.

  • I truly wanted to write a simple word in order to express gratitude to you for those precious tricks you are writing on this website. My time-consuming internet search has finally been recognized with awesome concept to share with my neighbours. I ‘d tell you that most of us readers are extremely blessed to be in a fine place with so many awesome individuals with very beneficial strategies. I feel truly blessed to have discovered your website page and look forward to many more entertaining moments reading here. Thank you once again for a lot of things.

  • thanks, I believe your visitors could possibly want significantly more articles or blog posts similar to this carry on the superior perform.

  • Thanks a lot this post, it is really fantastic!

  • Muchos Gracias for your post.Really thank you! Cool.

  • I need to to thank you for this excellent read!! I definitely enjoyed every bit of it. I’ve got you saved as a favorite to check out new stuff you post…

  • Here is my weblog mortgage