前面一直在尋找 MenuItem文字顏色設置。
我發現API唯一的背景顏色設置。
。。
因此,找到下面的方法。在OverFlow看到。
在onCreateOptionsMenu一下。
使MenuItem產生的ItemView去改動文字顏色
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
getLayoutInflater().setFactory(new Factory()
{
@Override
public View onCreateView(String name, Context context,
AttributeSet attrs)
{
System.out.println(name);
if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")
|| name.equalsIgnoreCase("com.android.internal.view.menu.ActionMenuItemView"))
{
try
{
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null, attrs);
System.out.println((view instanceof TextView));
if(view instanceof TextView){
((TextView)view).setTextColor(Color.GREEN);
}
return view;
} catch (InflateException e)
{
e.printStackTrace();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
return null;
}
});
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
能夠看到MenuItem的顏色成功改變。
<!------ 補充 這是近期發現的。
上面的 有些機型不能使用---------------->
看到:http://stackoverflow.com/questions/18015010/action-bar-menu-item-text-color stackOverFlow有相關解答。
版權聲明:本文博客原創文章。博客,未經同意,不得轉載。
