前面一直在找 MenuItem的文字颜色的设置。我发现API中只有背景颜色的设置。。。所以找到下面的方法。在OverFlow上看到的。

在onCreateOptionsMenu中覆写一下。使MenuItem产生的ItemView去修改文字颜色


@Overridepublic 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上有相关的答案。

更多相关文章

  1. android学习笔记23:幻灯片
  2. 自动化测试 Appium之Python运行环境搭建 Part2
  3. Android中Listview通过适配器设置Item的高度及其他样式
  4. Android使用饺子播放器播放服务器端的视频
  5. vapor开发随笔
  6. Android中ListView中使用CheckedTextView
  7. 解决Android创建AVD失败
  8. Android中一些实用的Tips
  9. Android(安卓)中状态栏(屏幕顶部)消息的显示 Notification

随机推荐

  1. Android(安卓)EditText不显示光标的解决
  2. android杀进程方法
  3. android:installLocation简析
  4. Android(安卓)build.gradle文件详解(转述
  5. android:screenOrientation横屏竖屏设置
  6. Android常用知识笔记
  7. Android(安卓)10ms问题:关于Android音频路
  8. Android(安卓)之 EditText属性用法介绍
  9. android 设置Button或者ImageButton的背
  10. Android(安卓)API中文文档ImageView