Quantcast
Channel: CoderzHeaven » actionbar textstyle
Viewing all articles
Browse latest Browse all 2

How to change title and Subtitle text color and size of ActionBar in Android?

$
0
0

Here is a simple example that shows how you can change title and subtitle textcolor and its size in Android

Method 1
——–

Changing the styles [For support Library]

Go to Values/styles.xml copy this code to change the textcolor and actionbar background color.


<style name="CustomActivityTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="actionBarStyle">@style/MyActionBar</item>
         <item name="android:windowActionBarOverlay">true</item>
        <!-- other activity and action bar styles here -->
</style>
      <!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="android:background">@drawable/actionbar_background</item>
        <item name="background">@drawable/actionbar_background</item>
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="android:subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
     </style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/color_title</item>
        <item name="android:textSize">12sp</item>
</style>
	  
	  

Note : For applying theme if you are not using the Support Library then change the AppCompat to Holo.

i.e make the Below changes in the parent

parent="@android:style/Theme.Holo.Light"

AND

parent="@android:style/Widget.Holo.Light.ActionBar"

AND for title

parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title"

Now Apply this theme in the AndroidManifest.xml, either for the entire application or a particular activity.

For example


 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomActivityTheme" >
        <activity
            android:name="com.example.actionbarcustomize.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 </application>
	

Make Sure you add the colors in the strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">ActionBarCustomize</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>

    <drawable name="actionbar_background">#FF0000</drawable>
    <color name="color_title">#00FF00</color>
	
</resources>

Method 2
———

You can use a simple java code to so this.

getActionBar().setTitle(Html.fromHtml("<font color='#ff0000'>ActionBartitle </font>"));

Note : Change getActionBar() to getSupportActionBar() if you are using the support library for ActionBar.

That’s all.. Now Run the application and see the changes.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images