Why is android activity action bar title black?

1.9k views Asked by At

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.

3

There are 3 answers

2
Anshul On BEST ANSWER

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.

1
mohammadreza khalifeh On

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

0
Zafar Kurbonov On

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