Manually adjusting the background color of the options menu bar

I noticed in devices of higher versions, the background color of the options menu is set to black by default. I need to change it to white, and the text color to black.

I searched this for a search and found many answers, but none of them seemed useful to me.

My suggestion adds this to my onCreateOptionsMenu:

getLayoutInflater().setFactory(new Factory() { @Override public View onCreateView(String name, Context context, AttributeSet attrs) { if (name .equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) { 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 .setBackgroundColor(Color.BLACK); // set the text color ((TextView) view).setTextColor(Color.WHITE); } }); return view; } catch (InflateException e) { } catch (ClassNotFoundException e) { } } return null; } }); return super.onCreateOptionsMenu(menu); 

But that did not help me.

+4
source share
1 answer

I was looking for stackoverflow and I think I found a suitable answer for your question.

Follow this link once ...

Set header background color

0
source

Source: https://habr.com/ru/post/1500482/


All Articles