我需要更改操作栏中操作栏文本,汉堡图标,溢出图标的颜色。我尝试了以下方法: -
<!-- Title text -->
<item name="android:textColorPrimary">@android:color/white</item>
<!-- Title color in AppCompat.Light -->
<item name="android:textColorPrimaryInverse">@android:color/white</item>
<!-- Menu text-->
<item name="actionMenuTextColor">@android:color/white</item>
<!-- Overflow -->
<item name="android:textColorSecondary">@android:color/white</item>
<!-- This will change drawer icon -->
<item name="android:popupBackground">@android:color/white</item>
但是上面的代码在很多其他地方强制颜色变化,比如叠加弹出,编辑文本文本颜色,有没有办法单独改变所需位置的颜色?
答案 0 :(得分:0)
有三种方法可以在ActionBar
中更改标题的前景色1.设置文本格式如下:
Spannable text = new SpannableString(actionBar.getTitle());
text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
actionBar.setTitle(text);
2.在ActionBar中设置自定义视图,如下所示:
ActionBar actionbar = getActionBar();
TextView textview = new TextView(MainActivity.this);
layoutparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
textview.setLayoutParams(layoutparams);
textview.setText("Action Bar Title Text");
textview.setGravity(Gravity.CENTER);
textview.setTextColor(Color.parseColor("#fc6902"));
textview.setTextSize(25);
actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionbar.setCustomView(textview);
完整的代码是there
3.使用html标签更改文字颜色
getSupportActionBar().setTitle((Html.fromHtml("<font color=\"#FF4444\">" + getString(R.string.some_string) + "</font>")));