0

I am pretty new to Android. I am working on an Activity where the user can press a button then a Color Picker Dialog which I have already implemented pops up. The user can choose between an array-list of different colors. Problem: I want that the color the user choosed will be applied on the ActionBar Top-Menu. Is there any possibility because I' ve only found solutions where the developer has to change the color "manually" in the code. I think I have to use the method public void onColorSelected(int color) which was implemented with the ColorPickerDialog but I don't have an idea how to link the ActionBar.

Thanks.

AndrIOS
  • 29
  • 1
  • Possible duplicate of [How to \_really\_ programmatically change primary and accent color in Android Lollipop?](http://stackoverflow.com/questions/25815769/how-to-really-programmatically-change-primary-and-accent-color-in-android-loll) – OneCricketeer Mar 25 '16 at 00:44

1 Answers1

0

You can change the color of the ActionBar like this:

//Change Color.GREEN for your own color from the Color Picker
ColorDrawable color = new ColorDrawable(Color.GREEN);
getSupportActionBar().setBackgroundDrawable(color);

If you are not using the support library use this instead:

//Change Color.GREEN for your own color from the Color Picker
ColorDrawable color = new ColorDrawable(Color.GREEN);
getActionBar().setBackgroundDrawable(color);
Leo
  • 834
  • 8
  • 14
  • Thanks for the answer. I've tried this but it gives me an error: "java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setBackgroundDrawable(android.graphics.drawable.Drawable)' on a null object reference" – AndrIOS Mar 26 '16 at 00:00
  • did you try with getSupportActionBar() too? – Leo Mar 26 '16 at 00:03