When using ActionMode, the status bar turns black on Lollipop
well your temporary solution is call this code when you most need it or when the problem starts
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP){
getWindow().setStatusBarColor(Color.BLUE);
// or Color.TRANSPARENT or your preferred color
}
EDIT
have you tried this
// actionMode.getCustomView().setBackgroundColor.(Color.TRANSPARENT);
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
//but this time you let the actionmode's view change the statusbar's
// visibility
actionMode.getCustomView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LOW_PROFILE); //or preferred one
return true;
}
when your actionMode
is destroyed, the status bar will be restored, so override that too and re-set your statusBar color.
hope it helps
I'm posting an answer here because, while the other solutions were helpful, none of them answered the question exactly. I was able to find out that the call to DrawerLayout.setStatusBarBackgroundColor()
was causing the trouble. My solution is the following:
Enable
windowTranslucentStatus
andwindowDrawsSystemBarBackgrounds
in the main theme.Remove the call to
DrawerLayout.setStatusBarBackgroundColor()
inside of myNavigationDrawerActivity
, from which allActivity
classes derive.Set the following styles in my
values-v21/styles.xml
base theme:<item name="android:colorPrimary">@color/app_green</item> <item name="colorPrimary">@color/app_green</item> <item name="android:colorPrimaryDark">@color/app_green_dark</item> <item name="colorPrimaryDark">@color/app_green_dark</item> <item name="android:colorPrimaryDark">?attr/colorPrimaryDark</item> <item name="android:statusBarColor">?attr/colorPrimaryDark</item>
Inside of the
NavigationDrawerActivity
class, in itsonCreate()
method, I execute the following (thanks @Tinadm for this part of the answer):getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Inside of my class that presents the
ActionMode
, I added the following methods:@Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // This is to highlight the status bar and distinguish it from the action bar, // as the action bar while in the action mode is colored app_green_dark getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.app_green_darker)); } // Other stuff... return true; } @Override public void onDestroyActionMode(ActionMode mode) { mActionMode = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.app_green_dark)); } }
Re-enabling the translucent status bar when the ActionMode
is destroyed enables my navigation drawer to be drawn underneath the status bar. It's also worth noting that the ActionMode
overlays the action bar, so it will overlay the navigation drawer if it's pulled out when the ActionMode
is enabled (via swiping left-to-right). I am going to disable this functionality when the ActionMode
is enabled, so it doesn't confuse users.
I was having the exactly same issue as you. I managed to solve it using a workaround.
- The first thing I did was to remove
windowTranslucentStatus=true
from my theme; - Then I used
getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
to make the content fill the area under the status bar. - I set
<item name="android:colorPrimaryDark">@color/primary_dark</item>
where primary_dark is "#51000000". Note the alpha value to achieve the same trasparency that windowTranslucent provides. Since my Toolbar is blue, my status bar is now dark blue. This alone did not solve the problem. When action mode is active, the status bar was still black in my case. But now, not using translucentStatusBar, I'm able to apply colors to my status bar, so I used:
@Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { getActivity().getWindow().setStatusBarColor(Color.parseColor("#026592")); return true; }
(Note that the color I used does not have alpha. This is the RGB color the exactly matches my dark blue semi transparent status bar).
I ran into the same problem a while ago and my resolution was to in onCreateActionMode & onDestroyActionMode set and restore the statusbar color.
//onCreateActionMode
mStartColor = activity.getWindow().getStatusBarColor();
getWindow().setStatusBarColor(color);
//onDestroyActionMode
activity.getWindow().setStatusBarColor(mStartColor);
Of course youll need to check that its on lolipop before using the setStatusBarColor method as its not available pre L.
Extra: If you use a DrawerLayout youll need to set the statusBarColor on it too.
mDrawerLayout.setStatusBarBackground(new ColorDrawable(color));
Hope that helps!