How could I change menu background color?
I try this but it is not work for me:
<style name="MyTheme" parent="@android:style/Theme" >
<item name="android:itemBackgroun开发者_运维百科d">@drawable/menuitem_background</item>
</style>
Could you help me?
Also I use this :
protected void setMenuBackground(){
getLayoutInflater().setFactory( new Factory() {
@Override
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 );
// Kind of apply our own background
new Handler().post( new Runnable() {
public void run () {
view.setBackgroundResource( R.drawable.background);
}
} );
return view;
}
catch ( InflateException e ) {
e.printStackTrace();
}
catch ( ClassNotFoundException e ) {
e.printStackTrace();
}
}
return null;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option_menu, menu);
setMenuBackground();
return true;
}
But I have the same result Nothing change
Use setMenuBackground ........
精彩评论