android - When using ActionMode, the status bar turns black on Lollipop -
i have status bar following in theme set on it:
<!-- base theme "material"-esque styles. use noactionbar can use toolbar @ runtime. --> <style name="material" parent="theme.appcompat.light.noactionbar"> <item name="android:windowdrawssystembarbackgrounds">true</item> <item name="android:windowtranslucentstatus">true</item> ... </style>
i have drawerlayout
of activities, sets color of status bar liking using:
mdrawerlayout.setstatusbarbackgroundcolor(getresources().getcolor(r.color.myapp_green));
i using toolbar
, rather default actionbar
, exists in layout (i.e. navigation drawer draws on top of it).
everything works fine, except in 1 of activities, have multi-select mode actionmode
. when actionmode
activated (using long press), overlays toolbar
using:
<item name="android:windowactionmodeoverlay">true</item> <item name="windowactionmodeoverlay">true</item> <item name="actionmodestyle">@style/material.widget.actionmode</item>
the material.widget.actionmode
style is:
<style name="material.widget.actionmode" parent="@style/widget.appcompat.actionmode"> <item name="android:background">@color/myapp_green</item> <item name="background">@color/myapp_green</item> </style>
now, problem that, whenever happens, status bar turns myapp_green
color black. it's if status bar translucency turned off (i'm using android 5.0). i'm wondering how might able behavior not happen, , keep status bar color/translucency as-is.
i've tried add <item name="android:windowtranslucentstatus">true</item>
action mode's styles, adding <item name="android:statusbarcolor">@color/myapp_green</item>
in style actionmode
, both without success.
update:
i wonder if has wonky way i'm setting status bar background. of activity classes derive navigationdraweractivity.java:
/** * {@link activity} supports navigation drawer, pull-out panel navigation * menus. drawer pulled out left side of screen (right side on rtl devices). */ public class navigationdraweractivity extends actionbaractivity implements adapterview.onitemclicklistener { private static final string logtag = navigationdraweractivity.class.getsimplename(); private drawerlayout mdrawerlayout; private listview mdrawerlist; private layoutinflater minflater; private navigationdraweritemadapter madapter; private actionbardrawertoggle mdrawertoggle; private navigationdraweritem[] mnavigationdraweritems; private toolbar mappbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // have call super.setcontentview() here because baseactivity redefines setcontentview(), // , don't want use that. super.setcontentview(r.layout.navigation_drawer); minflater = (layoutinflater) getsystemservice(context.layout_inflater_service); setupnavigationdrawer(); } @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); // sync toggle state after onrestoreinstancestate has occurred. mdrawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); mdrawertoggle.onconfigurationchanged(newconfig); } @override public boolean oncreateoptionsmenu(menu menu) { return true; } @override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); switch(id) { case android.r.id.home: return mdrawertoggle.onoptionsitemselected(item); } return super.onoptionsitemselected(item); } /** * toggles state of navigation drawer (i.e. closes if it's open, , opens if * it's closed). */ public void togglenavigationdrawer() { if (mdrawerlayout.isdraweropen(gravitycompat.start)) { closenavigationdrawer(); } else { opennavigationdrawer(); } } /** * opens navigation drawer. */ public void opennavigationdrawer() { mdrawerlayout.opendrawer(gravitycompat.start); } /** * closes navigation drawer. */ public void closenavigationdrawer() { mdrawerlayout.closedrawer(gravitycompat.start); } /** * initializes items specific navigation drawer. */ private void setupnavigationdrawer() { mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mdrawerlayout.setstatusbarbackgroundcolor(getresources().getcolor(r.color.wiw_green)); mappbar = (toolbar) findviewbyid(r.id.app_bar); setsupportactionbar(mappbar); actionbar actionbar = getsupportactionbar(); actionbar.setdisplayhomeasupenabled(true); actionbar.sethomebuttonenabled(true); actionbar.setdisplayshowhomeenabled(false); mdrawertoggle = new actionbardrawertoggle( this, /* our context (activity hosts drawer) */ mdrawerlayout, /* drawerlayout nav drawer drawn */ r.string.drawer_open, /* description of "open drawer", accessibility */ r.string.drawer_close /* description of "close drawer", accessibility */ ) { /** * called when drawer has settled in closed state. */ public void ondrawerclosed(view view) { super.ondrawerclosed(view); supportinvalidateoptionsmenu(); } /** * called when drawer has settled in open state. */ public void ondraweropened(view drawerview) { super.ondraweropened(drawerview); supportinvalidateoptionsmenu(); } }; mdrawerlist = (listview) mdrawerlayout.findviewbyid(r.id.drawer_list); mnavigationdraweritems = buildnavdraweritemslist(); setupadapter(mnavigationdraweritems); setupnavigationdrawerheader(); mdrawerlayout.setdrawerlistener(mdrawertoggle); mdrawerlist.setonitemclicklistener(this); } @override public void onitemclick(adapterview<?> parent, view aview, int aposition, long aid) { // code not relevant } /** * set inner content view of {@link navigationdraweractivity} have given layout. * * @param alayoutid id of layout load inner content view of activity. */ public void setdrawercontent(int alayoutid) { layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service); viewgroup root = (viewgroup)findviewbyid(r.id.drawer_content); inflater.inflate(alayoutid, root); } }
i have run drawerlayout.setstatusbarbackgroundcolor()
have effect. changing colorprimarydark
in values-v21/styles.xml
has no effect on status bar. feel root of problem... these classes being converted non-material theme new, material-like theme, i'm wondering if missed when did conversion colorprimarydark
recognized correctly.
i'm posting answer here because, while other solutions helpful, none of them answered question exactly. able find out call drawerlayout.setstatusbarbackgroundcolor()
causing trouble. solution following:
- enable
windowtranslucentstatus
,windowdrawssystembarbackgrounds
in main theme. - remove call
drawerlayout.setstatusbarbackgroundcolor()
inside ofnavigationdraweractivity
,activity
classes derive. - set following styles in
values-v21/styles.xml
base theme:
@color/app_green @color/app_green @color/app_green_dark @color/app_green_dark ?attr/colorprimarydark ?attr/colorprimarydark
inside of
navigationdraweractivity
class, inoncreate()
method, execute following (thanks @tinadm part of answer):getwindow().getdecorview().setsystemuivisibility(view.system_ui_flag_layout_stable | view.system_ui_flag_layout_fullscreen);
inside of class presents
actionmode
, added 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); // highlight status bar , distinguish action bar, // action bar while in action mode 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 translucent status bar when actionmode
destroyed enables navigation drawer drawn underneath status bar. it's worth noting actionmode
overlays action bar, overlay navigation drawer if it's pulled out when actionmode
enabled (via swiping left-to-right). going disable functionality when actionmode
enabled, doesn't confuse users.
Comments
Post a Comment