0

In my MainActivity.java is where I coded for my preference settings screen to work.

Here's my activity_main.xml design:

enter image description here

In the activity_main.xml design and text, you can see background colors for AppBarLayout and TabLayout are purple.

Here's my activity_main.xml text:

enter image description here

Yet the MainActivity bar is still blue. How do I turn it purple if in activity_main.xml it doesn't work anywhere. Do I have to add color in MainActivity.java class? How do I go about doing that?

K.Os
  • 5,123
  • 8
  • 40
  • 95
iBEK
  • 622
  • 2
  • 8
  • 27
  • https://stackoverflow.com/questions/41097686/dynamically-change-values-of-colors-xml-to-change-look-and-feel-of-android-app – phpdroid Oct 04 '17 at 18:36
  • 1
    Possible duplicate of [How to change programmatically background color of action bar items](https://stackoverflow.com/questions/25081706/how-to-change-programmatically-background-color-of-action-bar-items) – Pavneet_Singh Oct 04 '17 at 18:37
  • You can check this answer for your detailed [solution](https://stackoverflow.com/a/41380885/8387050) Thanks – Priya Oct 04 '17 at 18:40
  • Pavneet_Singh, my question is not a duplicate of the link you sent. The link you sent, solves PART of the problem but not the full problem. – iBEK Oct 04 '17 at 20:21

2 Answers2

0

Go to values folder and open color.xml

put your desired color in colorPrimary and colorPrimaryDark
For example :

<color name="colorPrimary">[Your Color]</color>
<color name="colorPrimaryDark">[Your Dark Color]</color>

That's it!!

Mayank Sharma
  • 739
  • 8
  • 13
0

Since my MainActivity bar is done programmatically, none of the above answers worked.

The only thing that worked for me is in my MainActivity.java class to programmatically add the following line:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
iBEK
  • 622
  • 2
  • 8
  • 27