简体   繁体   中英

Change ActionBar Color individually?

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM