Quando ur stanno gonfiando la chiamata menu di questo setMenuBackground metodo()
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.menu,menu);
setMenuBackground();
return true;
}
e scrivere questo nel metodo
protected void setMenuBackground(){
// Log.d(TAG, "Enterting setMenuBackGround");
getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context, AttributeSet attrs) {
if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try { // Ask our inflater to create the view
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null, attrs);
/* The background gets refreshed each time a new item is added the options menu.
* So each time Android applies the default background we need to set our own
* background. This is done using a thread giving the background change as runnable
* object */
new Handler().post(new Runnable() {
public void run() {
// sets the background color
view.setBackgroundResource(R.color.androidcolor);
// sets the text color
((TextView) view).setTextColor(Color.BLACK);
// sets the text size
((TextView) view).setTextSize(18);
}
});
return view;
}
catch (InflateException e) {}
catch (ClassNotFoundException e) {}
}
return null;
}});
}
fonte
2011-06-02 07:09:49
Se qualcuno è interessato ho risolto. http://pastebin.com/1QHGTMUW chiama semplicemente il setMenuBackground nel onCreate – rciovati
Ecco come ho ottenuto il colore di sfondo del menu della barra delle azioni personalizzato su Android 4.0 e versioni successive: http://stackoverflow.com/a/20077381/56285 – Jonik
provo codice, ma prima dimmi di rimuovere @Override e poi nothings. Ho provato a cambiare il colore di fondo del menù. – Kenji