android - ActionBarDrawerToggle won't appear in fragment -


i implemented this default fragment when navigation drawer fires , works, actionbardrawertoggle won't appear.

main activity:

public class mainactivity extends appcompatactivity implements navigationview.onnavigationitemselectedlistener{  private actionbardrawertoggle toggle;  protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      // initializing toolbar , setting actionbar     toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);      servicefragment servicefragment = new servicefragment();     fragmentmanager manager = getsupportfragmentmanager();     manager.begintransaction()             .replace(r.id.content_fragment, servicefragment)             .commit();     drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);      toggle = new actionbardrawertoggle(             this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close);     drawer.adddrawerlistener(toggle);     toggle.syncstate();      //initializing navigationview     navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view);      //this method triggers when item clicked in navigation drawer menu     navigationview.setnavigationitemselectedlistener(this);     } } 

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:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" tools:opendrawer="start">  <framelayout     android:layout_width="match_parent"     android:layout_height="match_parent"     app:layout_behavior="@string/appbar_scrolling_view_behavior"     android:id="@+id/content_fragment"/>  <android.support.design.widget.navigationview     android:id="@+id/nav_view"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_gravity="start"     android:fitssystemwindows="true"     app:headerlayout="@layout/nav_header_main"     app:menu="@menu/activity_main_drawer" /> 

default fragment, servicefragment inflates layout fragment_service.xml

<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/service_fragment">  <!-- todo: update blank fragment layout -->     <android.support.design.widget.coordinatorlayout         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:layout_height="match_parent"         android:background="@android:color/white"         android:fitssystemwindows="true"         >          <android.support.design.widget.appbarlayout             android:id="@+id/appbar"             android:layout_width="match_parent"             android:layout_height="@dimen/detail_backdrop_height"             android:fitssystemwindows="true"             android:theme="@style/themeoverlay.appcompat.dark.actionbar">              <android.support.design.widget.collapsingtoolbarlayout                 android:id="@+id/collapsing_toolbar"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:fitssystemwindows="true"                 app:contentscrim="?attr/colorprimary"                 app:expandedtitlemarginend="64dp"                 app:expandedtitlemarginstart="48dp"                 app:expandedtitletextappearance="@android:color/transparent"                 app:layout_scrollflags="scroll|exituntilcollapsed">                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="wrap_content">                     <!--android:scaletype="centercrop"-->                     <imageview                         android:id="@+id/backdrop"                         android:layout_width="match_parent"                         android:layout_height="match_parent"                         android:fitssystemwindows="true"                         android:scaletype="fitxy"                         app:layout_collapsemode="parallax" />                  </relativelayout>                 <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.collapsingtoolbarlayout>          </android.support.design.widget.appbarlayout>          <include layout="@layout/recyclerview"/>      </android.support.design.widget.coordinatorlayout> 

you need add toolbar following:

<?xml version="1.0" encoding="utf-8"?>     <android.support.v4.widget.drawerlayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitssystemwindows="true"     tools:opendrawer="start">       <include                 android:id="@+id/toolbar"                 layout="@layout/toolbar"                 android:layout_height="wrap_content"                 android:layout_width="match_parent"                 />      <framelayout         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior"         android:id="@+id/content_fragment"/>      <android.support.design.widget.navigationview         android:id="@+id/nav_view"         android:layout_width="wrap_content"         android:layout_height="match_parent"         android:layout_gravity="start"         android:fitssystemwindows="true"         app:headerlayout="@layout/nav_header_main"         app:menu="@menu/activity_main_drawer" /> 

& in fragment layout:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:card_view="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:clickable="true"     android:background="@android:color/white"     >        <include layout="@layout/recyclerview"/>          </linearlayout> 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -