set status bar color in DrawerLayout in Android -


i want set status bar color in custom drawerlayout default navigation drawee. work draweelayout should behind status bar , status bar color should custom. below v21\style.

<resources> <style name="apptheme.base" parent="theme.appcompat.light.noactionbar">     <item name="windowactionbar">false</item>     <item name="windownotitle">true</item>     <item name="android:statusbarcolor">@color/orange</item> </style> 

here activity_main.xml

    <android.support.v4.widget.drawerlayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitssystemwindows="false">      <linearlayout         android:layout_width="match_parent"         android:layout_height="50dp"         android:orientation="vertical"         >         <android.support.v7.widget.toolbar             android:id="@+id/my_awesome_toolbar"             android:layout_height="80dp"             android:layout_width="match_parent"             android:minheight="?attr/actionbarsize"             android:background="@color/orange"             android:fitssystemwindows="true"             />     </linearlayout>      <framelayout         android:layout_width="match_parent"         android:layout_height="50dp">          <linearlayout             android:id="@+id/llfirst"             android:layout_width="match_parent"             android:layout_height="50dp"             android:background="@color/orange"             android:layout_margintop="25dp"             android:orientation="horizontal">              <imageview                 android:id="@+id/imgmenu"                 android:layout_width="30dp"                 android:layout_height="30dp"                 android:layout_gravity="center"                 android:src="@drawable/menu" />         </linearlayout>     </framelayout>      <expandablelistview         android:id="@+id/lvleft"         android:layout_width="280dp"         android:layout_height="match_parent"         android:layout_gravity="start"         android:background="@color/white"         android:choicemode="singlechoice"         android:dividerheight="0dp"         />     </android.support.v4.widget.drawerlayout> 

here mainactivity.

    public class mainactivity extends activity implements view.onclicklistener, expandablelistview.onchildclicklistener {      private myadapter drawerlayoutadapter;     private drawerlayout drawer_layout;     private imageview imgmenu;     private arraylist<string> altemp;     private arraylist<mymodel> arraylist;     private expandablelistview expandblelis;      private activity activity;      @targetapi(build.version_codes.lollipop)     @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          setid();         setlistner();         setslidercolor();         slidemenu();         loadarraylist();         drawerlayoutadapter = new myadapter(mainactivity.this, arraylist);         expandblelis.setadapter(drawerlayoutadapter);         expandblelis.setonchildclicklistener(this);     }      private void setlistner()     {         imgmenu.setonclicklistener(this);          // used close child view on expandable listview , show 1 childview @ time.         expandblelis.setongroupexpandlistener(new expandablelistview.ongroupexpandlistener() {             int previousgroup = -1;              @override             public void ongroupexpand(int groupposition) {                 if(groupposition != previousgroup)                     expandblelis.collapsegroup(previousgroup);                 previousgroup = groupposition;             }         });     }     private void loadarraylist()     {          arraylist = new arraylist<mymodel>();         altemp = new arraylist<>();          //here have pur 0 position blank because on 0 position put profile picture layout.         arraylist.add(new mymodel("", 0, altemp));          altemp = new arraylist<>();         altemp.add("my profile");         arraylist.add(new mymodel("profile", r.drawable.profile, altemp));          altemp = new arraylist<>();         altemp.add("my transaction");          arraylist.add(new mymodel("transaction history", r.drawable.transaction, altemp));          altemp = new arraylist<>();         altemp.add("my setting");         arraylist.add(new mymodel("setting", r.drawable.setting, altemp));          altemp = new arraylist<>();         altemp.add("logout");         arraylist.add(new mymodel("log out", r.drawable.logout, altemp));     }       private void slidemenu()     {         try         {             drawerlayout.layoutparams layoutparams = (drawerlayout.layoutparams) expandblelis.getlayoutparams();             expandblelis.setlayoutparams(layoutparams);             expandblelis.setadapter(drawerlayoutadapter);              if (drawer_layout.isdraweropen(expandblelis))             {                 drawer_layout.closedrawer(expandblelis);             }              expandblelis.setonitemclicklistener(new adapterview.onitemclicklistener() {                 @override                 public void onitemclick(adapterview<?> parent, view view, final int pos, long id)                 {                     drawer_layout.setdrawerlistener(new drawerlayout.simpledrawerlistener() {                         @override                         public void ondrawerclosed(view drawerview)                         {                             super.ondrawerclosed(drawerview);                          }                     });                     drawer_layout.closedrawer(expandblelis);                     displayview(pos);                 }             });         } catch (exception e)         {             e.printstacktrace();         }     }      private void displayview(final int positiontitle)     {         try         {             closedrawer();             new handler().postdelayed(new runnable() {                 @override                 public void run()                 {                     switch (positiontitle)                     {                         case 0:                             break;                          case 1:                             break;                          case 2:                             break;                     }                 }             }, 200);         } catch (exception e)         {             e.printstacktrace();         }     }      private void setid()     {         try         {             drawer_layout = (drawerlayout) findviewbyid(r.id.drawer_layout);             imgmenu = (imageview) findviewbyid(r.id.imgmenu);              // below expandable listview.             expandblelis = (expandablelistview) findviewbyid(r.id.lvleft);             expandblelis.setdividerheight(1);             expandblelis.setgroupindicator(null);   // used hide expandable list symbol.             expandblelis.setclickable(true);          } catch (exception e)         {             e.printstacktrace();         }     }       public void opendrawer()     {         try         {             expandblelis.invalidateviews();             drawer_layout.opendrawer(expandblelis);         } catch (exception e)         {             e.printstacktrace();         }     }      private void closedrawer()     {         try         {             if (drawer_layout.isdraweropen(expandblelis))             {                 drawer_layout.closedrawer(expandblelis);             }         } catch (exception e)         {             e.printstacktrace();         }     }       @override     public void onclick(view v)     {         switch (v.getid())         {             case r.id.imgmenu:                  opendrawer();                  break;         }     }      @override     public boolean onchildclick(expandablelistview parent, view v,                                 int groupposition, int childposition, long id)     {         toast.maketext(mainactivity.this, "clicked on child",                 toast.length_short).show();         return true;     } } 

actually want implement custom drawer layout in status bar color should custom drawer layout should behind of status bar semi transparent. here have attach picture , want implement same. have try every solution not proper result please me solve such issue. in advance. enter image description here

i think looking scriminsetsframelayout.

here custom scriminsetsframelayout class can implement kind of behaviour

scriminsetsframelayout.java

public class scriminsetsframelayout extends framelayout {     private drawable minsetforeground;      private rect minsets;     private rect mtemprect = new rect();     private oninsetscallback moninsetscallback;      public scriminsetsframelayout(context context) {         super(context);         init(context, null, 0);     }      public scriminsetsframelayout(context context, attributeset attrs) {         super(context, attrs);         init(context, attrs, 0);     }      public scriminsetsframelayout(context context, attributeset attrs,             int defstyle) {         super(context, attrs, defstyle);         init(context, attrs, defstyle);     }      private void init(context context, attributeset attrs, int defstyle) {         final typedarray = context.obtainstyledattributes(attrs,                 r.styleable.scriminsetsview, defstyle, 0);         if (a == null) {             return;         }         minsetforeground =                 .getdrawable(r.styleable.scriminsetsview_insetforeground1);         a.recycle();          setwillnotdraw(true);     }      @override     protected boolean fitsystemwindows(rect insets) {         minsets = new rect(insets);         setwillnotdraw(minsetforeground == null);         viewcompat.postinvalidateonanimation(this);         if (moninsetscallback != null) {             moninsetscallback.oninsetschanged(insets);         }         return true; // consume insets     }      @override     public void draw(canvas canvas) {         super.draw(canvas);          int width = getwidth();         int height = getheight();         if (minsets != null && minsetforeground != null) {             int sc = canvas.save();             canvas.translate(getscrollx(), getscrolly());              // top             mtemprect.set(0, 0, width, minsets.top);             minsetforeground.setbounds(mtemprect);             minsetforeground.draw(canvas);              // bottom             mtemprect.set(0, height - minsets.bottom, width, height);             minsetforeground.setbounds(mtemprect);             minsetforeground.draw(canvas);              // left             mtemprect                     .set(0, minsets.top, minsets.left, height - minsets.bottom);             minsetforeground.setbounds(mtemprect);             minsetforeground.draw(canvas);              // right             mtemprect.set(width - minsets.right, minsets.top, width, height                     - minsets.bottom);             minsetforeground.setbounds(mtemprect);             minsetforeground.draw(canvas);              canvas.restoretocount(sc);         }     }      @override     protected void onattachedtowindow() {         super.onattachedtowindow();         if (minsetforeground != null) {             minsetforeground.setcallback(this);         }     }      @override     protected void ondetachedfromwindow() {         super.ondetachedfromwindow();         if (minsetforeground != null) {             minsetforeground.setcallback(null);         }     }      public void setoninsetscallback(oninsetscallback oninsetscallback) {         moninsetscallback = oninsetscallback;     }      public static interface oninsetscallback {         public void oninsetschanged(rect insets);     } } 

now regarding use of class.

-> activity_main.xml

<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitssystemwindows="true" >      <relativelayout         android:id="@+id/frame_container"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:fitssystemwindows="true" >          <include             android:id="@+id/toolbar_headers"             layout="@layout/toolbar_header"             android:visibility="invisible" />     </relativelayout>      <yourpackagename.scriminsetsframelayout         android:id="@+id/container"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_gravity="start"         android:layout_marginright="-8dp"         android:elevation="8dp"         android:fitssystemwindows="true"         app:insetforeground1="#4000" >          <!-- custom drawer layout -->         <include             android:id="@+id/drawar_layout"             layout="@layout/drawar_layout" />     </bhagyagold.com.extraclasses.scriminsetsframelayout>  </android.support.v4.widget.drawerlayout> 

here impotent tag android:fitssystemwindows check in views carefully.

-> java part

finally open or close drawer layout.

for e.g

mlayout = (scriminsetsframelayout) findviewbyid(r.id.container); mdrawerlayout.closedrawer(mlayout); 

-> styles.xml

<style name="apptheme" parent="theme.appcompat.light">         <item name="android:windowdrawssystembarbackgrounds">true</item>         <item name="colorprimary">@color/colorprimary</item>         <item name="colorprimarydark">@color/colorprimarydark</item>         <item name="coloraccent">colorprimarydark</item>         <item name="android:statusbarcolor">@android:color/transparent</item>         <item name="android:windowcontenttransitions">true</item>         <item name="android:windowallowentertransitionoverlap">true</item>         <item name="android:windowallowreturntransitionoverlap">true</item>         <item name="android:windowsharedelemententertransition">@android:transition/move</item>         <item name="android:windowsharedelementexittransition">@android:transition/move</item>         <item name="windownotitle">true</item>     </style> 

edit :

-> attrs.xml

<resources>      <declare-styleable name="scriminsetsview">         <attr name="insetforeground1" format="reference|color" />     </declare-styleable>  </resources> 

happy coding..


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -