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 > <!-- Text --> < 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" |
for ActionBar
parent="@android:style/Widget.Holo.Light.ActionBar" |
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 > |
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.
Dude!!! It is 6AM and I have been up a all night trying to get my code to work. Ive been searching for like 2 hours alone just for the title text. All the official examples are from before AppCompacActivity. Or maybe Im just dumb.
Either way your code worked and I am super grateful!
Thankyou
Thank you for help , after 8 hours it have done using your code thank you
Great