2

How can i change my action bar text color White to Black ? I don't want to use the Action Bar Sherlock .enter image description here

Here Is My Code For Action Bar .

ActionBar ab = getActionBar(); 
    ab.setDisplayUseLogoEnabled(false);
    ab.setDisplayShowHomeEnabled(true);
    ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    ab.setCustomView(R.layout.actionbar);
    ab.setDisplayHomeAsUpEnabled(true);
    ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#33CCFF"));     
    ab.setBackgroundDrawable(colorDrawable);

Here is Custom View For Action Bar :

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/title"
    android:textColor="#ffffff"
    android:textSize="24sp" />
</LinearLayout>

Here style.xml :

    <resources>
    <style name="AppBaseTheme"  parent="@android:style/Theme.Holo.Light">
    </style>
    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
    </style>
</resources>

May I know what is the correct way to achieve my objective?Maybe this question too basic, but i did't find any suitable solution.Please Help me out.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198

4 Answers4

0

Try this styles:

You can edit your TitleTextStyle inside of styles:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>

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

  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/black</item>
  </style>
</resources>
Lokesh
  • 5,180
  • 4
  • 27
  • 42
0

Here is the styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

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

<style name="MyTheme.ActionBar.TitleTextStyle" 
parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style></resources>

thanx to rnoway

Sanu
  • 455
  • 1
  • 6
  • 17
0
  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/title"
    android:textColor="#ffffff"      //  change the color code your wat , instead of #ffffff put youra
    android:textSize="24sp" />

u can find the color codes from

http://www.w3schools.com/tags/ref_colorpicker.asp

kathir
  • 489
  • 2
  • 11
0

Just use html to set the title, and specify the text color. For example, to set the ActionBar text color to red, simply do this:

getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color=\"#000000\">" + getString(R.string.app_name) + "</font>"));
Shyam
  • 6,376
  • 1
  • 24
  • 38