Android 5.0 material design style navigation drawer for KitKat -
Android 5.0 material design style navigation drawer for KitKat -
i see android introduced new navigation drawer icons, drawer icon , arrow icon. how can utilize in kitkat supported apps. see google's latest version of newsstand app, has latest navigation drawer icons , animations. how can implement that?
i have tried setting minsdk 19 , complilesdk 21 it's using old style icons. self implemented?
you need utilize new toolbar in appcompat v21 , new actionbardrawertoggle
in library well.
add gradle dependency gradle file:
compile 'com.android.support:appcompat-v7:21.0.0'
your activity_main.xml
layout that:
<!--i utilize android:fitssystemwindows because changing color of statusbar well--> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_parent_view" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:fitssystemwindows="true"> <include layout="@layout/toolbar"/> <android.support.v4.widget.drawerlayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- main layout --> <framelayout android:id="@+id/main_fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- nav drawer --> <fragment android:id="@+id/fragment_drawer" android:name="com.example.packagename.drawerfragment" android:layout_width="@dimen/drawer_width" android:layout_height="match_parent" android:layout_gravity="left|start" /> </android.support.v4.widget.drawerlayout> </linearlayout>
your toolbar layout that:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" app:theme="@style/themeoverlay.appcompat.actionbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minheight="?attr/actionbarsize" android:background="?attr/colorprimary"/>
your activity must extend from:
actionbaractivity
when find views (drawer , toolbar) in activity set toolbar back upwards action bar , set setdrawerlistener:
setsupportactionbar(mtoolbar); mdrawertoggle= new actionbardrawertoggle(this, mdrawerlayout,mtoolbar, r.string.app_name, r.string.app_name); mdrawerlayout.setdrawerlistener(mdrawertoggle);
after need take care of menu items , drawertoogle state:
@override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = new menuinflater(this); inflater.inflate(r.menu.menu_main,menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { if (mdrawertoggle.onoptionsitemselected(item)) { homecoming true; } homecoming super.onoptionsitemselected(item); } @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); mdrawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); mdrawertoggle.onconfigurationchanged(newconfig); } @override public void onbackpressed() { if(mdrawerlayout.isdraweropen(gravity.start|gravity.left)){ mdrawerlayout.closedrawers(); return; } super.onbackpressed(); }
the implementation same before toolbar , receive arrow animation free. no headaches. more info follow:
the documentation.
the chrisbanes post
the official android blog post.
if want display drawer on toolbar , under status bar, please refer this question.
edit: utilize navigationview back upwards design library. tutorial larn how utilize in here: http://antonioleiva.com/navigation-view/
android navigation-drawer android-5.0-lollipop
Comments
Post a Comment