我已使用以下代码成功自定义选项菜单的背景。
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);
/*
* 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() {
view.setBackgroundResource(R.drawable.blue_bg_pixel);
}
});
return view;
}
catch (InflateException e) {
}
catch (ClassNotFoundException e) {
}
}
return null;
}
});
现在我必须自定义菜单大小,文字大小/颜色。任何人都可以帮助我。
提前致谢。
答案 0 :(得分:0)
这在Android 2.3上失败
请参阅 http://code.google.com/p/android/issues/detail?id=4441#c6 和 Change menu background color on android 2.3
了解详情
答案 1 :(得分:0)
宽度,高度你需要黑客行动吧。
但是如果你需要自定义,请使用:ActionBar Generator({{3p>