0

I need to change the color of the action bar text, hamburger icon,overflow icon in the action bar. I tried the following:-

 <!-- 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>

But the above code forces color change in many other places, like the overlay popup, edit text text color, is there any way to change the color in the desired place alone?

Sreekanth Karumanaghat
  • 3,383
  • 6
  • 44
  • 72

1 Answers1

0

There are 3 way to change forecolor of the title in ActionBar

1.Setting text format just like this :

Spannable text = new SpannableString(actionBar.getTitle());
    text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    actionBar.setTitle(text);

2.Setting custom view in your ActionBar just like this:

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);

full of code is there

3.Changing text color using html tags

getSupportActionBar().setTitle((Html.fromHtml("<font color=\"#FF4444\">" + getString(R.string.some_string) + "</font>")));
ziLk
  • 3,120
  • 21
  • 45