1

I want to give the rgb color to the application title string in my application string in the resource file I have declared like this,

<string name="app_name">MyApplication</string>

and used it to set the title in manifest file like this,

<activity
        android:name=".MainActivity"
        android:screenOrientation="portrait" 
        android:theme="@style/MyTheme"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"> 

I want to give different color to My and Application words, rgb(201,89,51) for My and rgb(74,137,174) respectively

How can I do this?

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
Sandhu
  • 141
  • 2
  • 10
  • what? you cannot do that – Randyka Yudhistira Mar 09 '15 at 07:58
  • [This](http://stackoverflow.com/questions/15948026/cant-change-the-text-color-with-android-action-bar-drop-down-navigation) might help you. **OR** the best and easy way to get it is by using a TextView on top with the colored text ( using Html.fromHtml) and using FullScreenActivity. – Tushar Gogna Mar 09 '15 at 08:01
  • And [this](http://javatechig.com/android/actionbar-with-custom-view-example-in-android) also. – Phantômaxx Mar 09 '15 at 08:02

2 Answers2

0

try this

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

if you are using appcompact :

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ff0000'>My</font><font color='#ff00ff'>Application</font>"));
Nooh
  • 1,548
  • 13
  • 21
  • it worked, thanks a lot. Come to know about using HTML in android code, used for first time – Sandhu Mar 09 '15 at 08:19
0

Have you tried Html.fromHtml(String s) ? output gives you styled by HTML text. An example:

String styledText=Html.fromHtml("<font color="#123456">My</font> <font color="#654321">App</font>");

and then set:

Window w = getWindow();
w.setTitle(styledText);

or

getSupportActionBar().setTitle(styledText);
//getActionBar().setTitle(styledText);
snachmsm
  • 17,866
  • 3
  • 32
  • 74