我已经完成了我的选项菜单,但它像列表视图一样显示,但我需要像按钮矩形这样的样式。
我的选项菜单
我需要像这样的选项菜单
如何更改选项菜单样式?
问候,
只需删除文件夹 values-v11 , values-v14 等,不要删除默认值文件夹。
我就是这样做的:
public boolean onCreateOptionsMenu(Menu menu)
{
CambiarFondoMenuInflater();
return Menus.CrearMenus(contexto,menu, TipoMenu.PRINCIPAL);
}
CambiarFondoMenuInflater() 方法:
protected void CambiarFondoMenuInflater()
{
final LayoutInflater infl = getLayoutInflater();
infl.setFactory(new Factory()
{
public View onCreateView(final String name,
final Context context,
final AttributeSet attrs)
{
if (!name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView"))
return null;
View view = null;
if (IconMenuItemView_class == null)
{
try
{
IconMenuItemView_class = getClassLoader().loadClass(name);
}
catch (ClassNotFoundException e)
{
return null;
}
}
if (IconMenuItemView_class == null)
return null;
if (IconMenuItemView_constructor == null)
{
try
{
IconMenuItemView_constructor =
IconMenuItemView_class.getConstructor(standard_inflater_constructor_signature);
}
catch (SecurityException e)
{
return null;
}
catch (NoSuchMethodException e)
{
return null;
}
}
if (IconMenuItemView_constructor == null)
return null;
try
{
Object[] args = new Object[] { context, attrs };
view = (View)(IconMenuItemView_constructor.newInstance(args));
}
catch (IllegalArgumentException e)
{
return null;
}
catch (InstantiationException e)
{
return null;
}
catch (IllegalAccessException e)
{
return null;
}
catch (InvocationTargetException e)
{
return null;
}
if (null == view)
return null;
final View v = view;
new Handler().post(new Runnable()
{
public void run()
{
v.setBackgroundColor(Color.BLACK);
try
{
// Here you can change whatever you want :)
TextView tv = (TextView)v;
tv.setTextColor(Color.WHITE);
}
catch (ClassCastException e)
{
// Don't set TextView attributes
}
}
});
return view;
}
});
}
此信息取自本网站上的帖子。我已经搜索过了,但我找不到它,所以我把我的代码放在这里。如果有人可以参考它,我将非常感激。