0

donc im construire l'application android dans mon activité principale im en utilisant la barre d'outils effondrement avec tiroir de navigation, mais le bouton de tuggle pour le navigationDrawer ne montre pas. donc je besoin d'un moyen de faire la bascule apparaît spécialement lorsque la barre d'outils se sont effondrésRéduire la barre d'outils avec le bouton bascule NavigationDrawer ne montrant pas

c'est mon content_main:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 

    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.infinity.dev.nearby.Main2Activity" 
    tools:showIn="@layout/app_bar_main2" 
    android:background="@color/grey" 
    android:fillViewport="false"> 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/MyAppbar" 
     android:layout_width="match_parent" 
     android:layout_height="256dp" 
     android:fitsSystemWindows="true"> 
    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapse_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     app:contentScrim="@color/colorPrimary" 
     android:fitsSystemWindows="true"> 

    <ImageView 
     android:id="@+id/bgheader" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="centerCrop" 
     android:background="@drawable/france" 
     android:fitsSystemWindows="true" 
     app:layout_collapseMode="pin" /> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/MyToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      style="@style/AppTheme" 

      app:layout_collapseMode="parallax" /> 



    </android.support.design.widget.CollapsingToolbarLayout> 


    </android.support.design.widget.AppBarLayout> 
<android.support.v4.widget.NestedScrollView...> 

</android.support.design.widget.CoordinatorLayout> 

et c'est le 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"> 

     <include 
      layout="@layout/app_bar_main2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 



     <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_main2" 
      app:menu="@menu/activity_main2_drawer" 
      app:itemTextColor="#212121" 
      /> 

    </android.support.v4.widget.DrawerLayout> 

c'est le app_bar_main.xml:

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main2" /> 

c'est le code utilisé dans main_activity.java:

final Toolbar toolbar = (Toolbar) findViewById(R.id.MyToolbar); 
setSupportActionBar(toolbar); 
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapse_toolbar); 
collapsingToolbarLayout.setTitle("My Country"); 
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
drawer.setDrawerListener(toggle); 
toggle.syncState(); 

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
navigationView.setNavigationItemSelectedListener(this);      

collapsingToolbarLayout.setContentScrimColor(ContextCompat.getColor(context,R.color.colorPrimary)); 

image of toolbar before collapse:

image of toolbar after Collapse

Répondre

1

Il pourrait y avoir deux raisons pour cela, faire une chose essayer de cliquer sur sur la place du bouton bascule, si elle ouvre le tiroir signifie que votre bascule n'est pas visible en raison du style de votre thème, donc vous pouvez changer lorof votre bascule du thème, sinon celui-ci:

<?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:context=".ui.MainActivity"> 


    <android.support.design.widget.CoordinatorLayout 
       android:id="@+id/htab_maincontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/htab_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/htab_collapse_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="320dp" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"> 

      <ImageView 
       android:id="@+id/bgheader" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/france" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="104dp" 
       android:gravity="top" 
       android:minHeight="?attr/actionBarSize" 

       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:layout_scrollFlags="scroll|enterAlways|snap" 
       app:layout_collapseMode="pin" 

       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 


    </android.support.design.widget.AppBarLayout> 


    </android.support.design.widget.CoordinatorLayout> 

    <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" 
    app:menu="@menu/nav_items" /> 
    </android.support.v4.widget.DrawerLayout> 



This might be useful for you ,try to use this one