菜单背景在设备上不可见
我想为菜单按钮设置背景图像。我可以在模拟器上看到图像,但是当我在设备上运行应用程序时,它不显示任何背景图像,而只显示透明的白色背景。 我已经像这样设置了背景
protected void setMenuBackground(){
getLayoutInflater().setFactory( new Factory() {
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 () {
view.setBackgroundResource( R.drawable.menubuttons_bg );
}
} );
return view;
}
catch ( InflateException e ) {}
catch ( ClassNotFoundException e ) {}
}
return null;
}});
}
I want to set background image for menu buttons. I can see the image on emulator, but when I run the app on device it does not show any background image, but only transparent white background.
I have set the background like this
protected void setMenuBackground(){
getLayoutInflater().setFactory( new Factory() {
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 () {
view.setBackgroundResource( R.drawable.menubuttons_bg );
}
} );
return view;
}
catch ( InflateException e ) {}
catch ( ClassNotFoundException e ) {}
}
return null;
}});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里
您正在设置视图的背景
我认为您正在寻找将其设置在按钮上
here
you are setting the background on the view
I think you are looking to set it on the button