5

When I made projects using Android Studio before, the activity action bar title was white by default. I created a new project with same settings as the previous projects (API level 11), but the default color of the activity title color is black. I didn't change anything at all, this is a fresh project. I tried using styles but nothing is working.

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Cs_Is_Better
  • 121
  • 9

3 Answers3

1

The action bar title color for a new project depends on the default theme used.In case of dark action bar the title color is white,please go and check the theme used in manifest.

Anshul
  • 79
  • 4
  • It uses the default theme, which is this. ` ` \n I'm sorry for the messy code. Don't know how to format it in this site. – Cs_Is_Better Sep 09 '17 at 18:56
  • try replacing "Theme.AppCompat.Light" by "Theme.AppCompat.Light.DarkActionBar" when your action bar theme is dark the title automatically gets light & for adding any code on here just give four spaces before the line it will get formatted – Anshul Sep 09 '17 at 19:09
0

in order to change the color of actionbar title you can you can use this code in your class :

actionBar.setTitle(Html.fromHtml("<font color='#ffffff'>ActionBarTitle </font>"));
// to choose white 

or change your actionbar style in res/values/styles.xml file:

<resources>
    <style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
    </style>

    <style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">ANY_HEX_COLOR_CODE</item>
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    </style>
</resources>

keep in mind you should change the style you chose before in manifest.xml for your app

mohammadreza khalifeh
  • 1,510
  • 2
  • 18
  • 32
0

If you want to change it programmatically below is the code.

The ActionBar ID is not available directly, so you have to do little bit of hacking here.

 int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
if (actionBarTitleId > 0) {
    TextView title = (TextView) findViewById(actionBarTitleId);
    if (title != null) {
        title.setTextColor(Color.RED);
    }
}
Zafar Kurbonov
  • 2,077
  • 4
  • 19
  • 42