Home button not showing up in navigation drawer android -
i'm using navigation drawer
project, working fine 1 small problem, arrow
displayed not home
button. tried found in documentations, forums , here nothing working.
what tried far:
mdrawertoggle.syncstate(); actionbar.setdisplayshowtitleenabled(true); actionbar.setdisplayhomeasupenabled(true); @override public void onpostcreate(bundle savedinstancestate, persistablebundle persistentstate) { super.onpostcreate(savedinstancestate, persistentstate); mnavigationdrawerfragment.getmdrawertoggle().syncstate(); } actionbar actionbar = getsupportactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_standard); actionbar.setdisplayshowtitleenabled(true); actionbar.setdisplayhomeasupenabled(true); actionbar.sethomebuttonenabled(true); actionbar.settitle(mtitle);
navigationdrawerfragment:
// defer code dependent on restoration of previous instance state. mdrawerlayout.post(new runnable() { @override public void run() { mdrawertoggle.syncstate(); } });
i have been busy making simple app navigation drawer..don't use template there deprecated methods.. working.. created example.. try this..
your mainactivity
public class mainactivity extends actionbaractivity { toolbar toolbar; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar = (toolbar) findviewbyid(r.id.app_toolbar); setsupportactionbar(toolbar); profile profile = (profile) getsupportfragmentmanager().findfragmentbyid(r.id.profilefragmentinmain); profile.setup((drawerlayout) findviewbyid(r.id.drawer),toolbar); } @override public boolean onoptionsitemselected(menuitem item) { return super.onoptionsitemselected(item); }
this fragment..
public class profile extends fragment { actionbardrawertoggle drawertoggle; drawerlayout mdrawerlayout; @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.profile, container, false); return view; } public void setup(drawerlayout drawerlayout, toolbar toolbar) { mdrawerlayout = drawerlayout; drawertoggle = new actionbardrawertoggle(getactivity(), drawerlayout, toolbar, r.string.open, r.string.close){ @override public void ondraweropened(view drawerview) { super.ondraweropened(drawerview); getactivity().invalidateoptionsmenu(); } @override public void ondrawerclosed(view drawerview) { super.ondrawerclosed(drawerview); getactivity().invalidateoptionsmenu(); } @override public boolean onoptionsitemselected(menuitem item) { if (item != null && item.getitemid() == android.r.id.home) { if (mdrawerlayout.isdraweropen(gravity.right)) { mdrawerlayout.closedrawer(gravity.right); } else { mdrawerlayout.opendrawer(gravity.right); } return true; } return false; } }; mdrawerlayout.setdrawerlistener(drawertoggle); mdrawerlayout.post(new runnable(){ @override public void run(){ drawertoggle.syncstate(); } }); } }
this in classes..
now xml layouts..
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:id="@+id/drawer" android:layout_height="match_parent" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".mainactivity"> <include android:id="@+id/app_toolbar" layout="@layout/toolbar"/> </linearlayout> <fragment android:id="@+id/profilefragmentinmain" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" app:layout="@layout/profile" android:name="com.example.ajay.myapplication.profile" tools:layout="@layout/profile"/> </android.support.v4.widget.drawerlayout>
your profile.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" app:theme="@android:style/theme.holo.light.dialogwhenlarge.noactionbar"> </linearlayout>
your toolbar.xml
<?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:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/app_toolbar" />
previews :
open drawer
closed drawer
additional info : have added toolbar material design implemetation of actionbar. latest way create actionbar. can use that. in case, select theme noactionbbar in styles.xml file.
Comments
Post a Comment