Android(安卓)MenuItem 设置文本颜色-TextColor设置
16lz
2021-01-26
前面一直在寻找 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有相关解答。
版权声明:本文博客原创文章。博客,未经同意,不得转载。
更多相关文章
- android画图----ShapeDrawable和shader
- Android通知栏颜色改变方法
- android-ProgressBar
- Android中visibility属性详解
- Android动态壁纸解析
- android中多语言的设置
- android 渐变
- Android实现沉浸式状态栏的那些坑
- Android(安卓)Studio -添加你见过的最牛Log*神器*