更改android 2.3上的菜单背景颜色
如何更改菜单背景颜色?
我尝试了这个,但它对我不起作用:
<style name="MyTheme" parent="@android:style/Theme" >
<item name="android:itemBackground">@drawable/menuitem_background</item>
</style>
你能帮助我吗?
我也用这个:
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;
}
但我有相同的结果没有任何改变
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:itemBackground">@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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用setMenuBackground........
Use setMenuBackground ........