版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Bu_siliang/article/details/85321373
项目中我们经常用到menu菜单栏,系统给出的默认为黑色的,有时候不符合我们项目中的需要,这就需要我们对状态栏给出一些改变。
:
- 解决方案一:在style中配置给出menu的样式,通常情况下,这种方案能决绝大部分需求
<style name="MenuTextStyle">
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">@dimen/px_to_sp_40</item>
</style>`
2;主题中引入
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionMenuTextColor">@color/white</item>
<item name="android:windowContentOverlay">@null</item>
<item name="actionMenuTextAppearance">@style/MenuTextStyle</item>
</style>
但有时候你会发现在一些手机上不好使,由于公司采用的定制机,是5.0,你会发现没有用,于是问度娘,发现千篇一律,也没啥用,还是自己来。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//修改字体的颜色
getMenuInflater().inflate(R.menu.menu_search, menu);
MenuItem item = menu.findItem(R.id.btnAdd);
SpannableString spannableString = new SpannableString(item.getTitle());
spannableString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spannableString.length(), 0);
item.setTitle(spannableString);
return true;
}
你会发现解决了哈哈。如果有不知道 SpannableString这个api的可以问度娘,你会发现,不一样的精彩。。。