2

Is it possible to change the colour of the title text within the action bar to a colour of a hex value? I'm only aware of the following and have no idea if this can be achieved:

setTitleColor(Color.Green);
wbk727
  • 8,017
  • 12
  • 61
  • 125
  • This seems to have been answered already: [http://stackoverflow.com/questions/2386867/how-to-change-title-bar-color-in-android-activity][1] [http://stackoverflow.com/questions/2251714/set-title-background-color][2] [1]: http://stackoverflow.com/questions/2386867/how-to-change-title-bar-color-in-android-activity [2]: http://stackoverflow.com/questions/2251714/set-title-background-color – ifconfig Sep 05 '14 at 00:01
  • None of those links show code like the one above but with a hex value – wbk727 Sep 05 '14 at 00:04
  • `this` totally has its place there, I meant to ask what class does it represent? – Alexis Leclerc Sep 05 '14 at 00:06
  • The `setTitleColor(...)` method you are calling is part of a class. Can you tell me what is that class? – Alexis Leclerc Sep 05 '14 at 00:13

2 Answers2

4

Android < 4.0

You can simply do setTitleColor(Color.parseColor("#000000"));.

Android >= 4.0

Check this answer https://stackoverflow.com/a/10592561.

Community
  • 1
  • 1
FyodorX
  • 1,490
  • 2
  • 19
  • 23
  • I've done exactly that but the text is still white. Btw my app is targeting <= 4.1. `@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getActionBar().setTitle("Welcome"); ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFCC00"))); setTitleColor(Color.parseColor("#000099")); }` – wbk727 Sep 05 '14 at 12:35
  • It depends on the SDK you're using to execute it, not the SDK's you're theoretically targeting. Try doing what the answer linked specifies. – FyodorX Sep 05 '14 at 13:16
  • I am using Android Studio - is that what you mean by SDK? – wbk727 Sep 05 '14 at 13:47
  • No, I mean your device's or AVD's Android version. Anyway, if the first solution doesn't work for you, then you're probably running KitKat and you should check http://stackoverflow.com/a/10592561 – FyodorX Sep 05 '14 at 14:00
  • So just to confirm the code you suggested - does go in the 'protected void OnCreate...' part of the java file? – wbk727 Sep 05 '14 at 14:49
  • Yes, that could be anywhere in the context of an `Activity`. – FyodorX Sep 05 '14 at 14:58
  • My project is using SDK version 19 and the emulator is using Android version 19 (4.4.2 KitKat). Is there anything wrong with that? – wbk727 Sep 05 '14 at 15:10
  • No, but since KitKat the first solution doesn't work. You have to follow this: http://stackoverflow.com/a/10592561 – FyodorX Sep 05 '14 at 15:13
  • So are you saying this can't be done programmatically now then? – wbk727 Sep 05 '14 at 16:00
  • No, I'm pointing you to the answer you're looking for: http://stackoverflow.com/a/10592561. – FyodorX Sep 05 '14 at 16:05
0

You can add hex color values on your color.xml. Then on your activity you try to add this line of code:

setTitleColor(getResources().getColor(R.color.hex_color_id));
yhel
  • 92
  • 1
  • 6
  • So I can't do something like this then? `setTitleColor(new ColorDrawable(Color.parseColor("#0099CC")));` – wbk727 Sep 05 '14 at 00:31
  • 1
    If it works then you can, but if not you can try another way. Don't just stick into one option there are so many ways. – yhel Sep 05 '14 at 00:35