Android Home button on Action Bar Does Not Appear -
i came across strange problem home button on toolbar not showing.
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:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:elevation="@dimen/design_navigation_elevation" android:fitssystemwindows="true" tools:context="my.app.mainactivity"> <android.support.design.widget.coordinatorlayout android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/toolbar"/> <include layout="@layout/content_main"/> <include layout="@layout/fab"/> </android.support.design.widget.coordinatorlayout> <android.support.design.widget.navigationview android:id="@+id/navigation_drawer" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerlayout="@layout/navigation_drawer_header" app:menu="@menu/menu_navigation_drawer"/> </android.support.v4.widget.drawerlayout>
toolbar.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.appbarlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_height="wrap_content" android:layout_width="match_parent" android:theme="@style/apptheme.appbaroverlay"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="?attr/colorprimary" app:popuptheme="@style/apptheme.popupoverlay" /> </android.support.design.widget.appbarlayout>
mainactivity.java
public class mainactivity extends appcompatactivity { private toolbar toolbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); getsupportactionbar().setdisplayshowhomeenabled(true);
i have app using same method, working fine. idea?
you have :
<android.support.design.widget.navigationview android:id="@+id/navigation_drawer" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerlayout="@layout/navigation_drawer_header" app:menu="@menu/menu_navigation_drawer"/>
which has default icon:
and take @ blog: codetheory.in (web.archive)
which says:
sethomebuttonenabled(boolean enabled)
this method similar previous one(
setdisplayhomeasupenabled(boolean showhomeasup
)) actually, except left-facing caret doesn’t show unlessandroid:parentactivityname
specified.
instead, try use:
getsupportactionbar().setdisplayhomeasupenabled(true);
then, it should work without drawer
guess.because has default icon.
check results without drawer
suggested code:
somehow, don't need that.
Comments
Post a Comment