Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Status Bar color when entering Contextual Action Mode

Tags:

I have an application that uses theme attribute (colorPrimaryDark) to color the Status Bar on Android v21+:

enter image description here

This is working fine. Now, when user long-presses a list item and enters the contextual action mode, I am able to color the CAB bar using attribute actionModeBackground so it looks like this:

enter image description here

So the action bar is gray, which is what I want, but the status bar is still colored using the theme dark color. I don't want that, I want to change it to dark gray or black.

How can I do this? I don't see any theme attribute that would work here.

like image 551
Greg Ennis Avatar asked Apr 14 '15 03:04

Greg Ennis


People also ask

How can I change the color of my status bar in particular activities?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.

What is contextual action bar?

The contextual action mode is a system implementation of ActionMode that focuses user interaction toward performing contextual actions. When a user enables this mode by selecting an item, a contextual action bar appears at the top of the screen to present actions the user can perform on the currently selected item(s).

How can I change my status bar style in Android?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.


1 Answers

    private int statusBarColor;      @Override     public boolean onCreateActionMode(ActionMode mode, Menu menu) {         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {             //hold current color of status bar             statusBarColor = getWindow().getStatusBarColor();             //set your gray color             getWindow().setStatusBarColor(0xFF555555);         }         ...     }      ...      @Override     public void onDestroyActionMode(ActionMode mode) {         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {             //return to "old" color of status bar             getWindow().setStatusBarColor(statusBarColor);          }         ...     } }); 
like image 181
user3484802 Avatar answered Sep 28 '22 18:09

user3484802