0

Я создал активность tablayout с помощью viewPager для транзакции фрагмента.Навигационная панель значок гамбургера не работает

Теперь мой проект изменился и будет добавлен ящик. В этом меню гамбургера не работает. При прокручивании слева появляется и когда я нажимаю значок, он не отображается. Я думаю, что это может быть проблема с макетом. Но я изо всех сил исправляю макет.

Я пробовал, но весь фрагмент движется вверх, если я меняю положение выдвижного ящика.

Планировка:

<android.support.design.widget.CoordinatorLayout 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="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/olive" 
      app:tabMode="scrollable" 
      app:tabGravity="fill"/> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:id="@+id/drawerLayout"> 
     <FrameLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/containerView"> 
     </FrameLayout> 
     <android.support.design.widget.NavigationView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:id="@+id/shitstuff" 
      app:itemTextColor="@color/black" 
      app:menu="@menu/drawermenu" 
      android:layout_marginTop="-24dp"/> 
    </android.support.v4.widget.DrawerLayout> 
</android.support.design.widget.CoordinatorLayout> 

ответ

0

отдельный файл для вкладок макета, чтобы прикрепить все вкладки в этом.

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 
    tools:context="helix.profitkey.hotelapp.SimpleTabsActivity"> 

    <include layout="@layout/status_bar"/> 
    <android.support.design.widget.CoordinatorLayout 
    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" 
    android:fitsSystemWindows="true" 
    tools:context="helix.navigationdrawer.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/tab_selected_color" 
      app:tabTextColor="@color/silver" 
      app:tabSelectedTextColor="@color/white" 
      app:tabMode="scrollable" 
      app:tabGravity="fill" 
      /> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

Затем XML прикрепляется в макете ящика. Внутри ящика я использовал навигационное представление, чтобы добавить список опций или действий. Приложение навигации: menu = "@ menu/drawermenu", это добавит список элементов из drawermenu.

mainactivity.xml

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:id="@+id/drawerLayout"> 
    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:background="@color/violet_light" 
     android:layout_gravity="start" 
     android:id="@+id/drawerstuff" 
     app:itemTextColor="@color/violet_statusbar" 
     app:menu="@menu/drawermenu" 
     android:theme="@style/NavigationTheme" 
     android:layout_marginTop="-24dp"/> 

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

@ меню/drawermenu.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:title="Title" 
    android:id="@+id/id" 
    android:icon="@drawable/tyre"/> 

<item android:title="Title" 
    android:id="@+id/id1" 
    android:icon="@drawable/tyre"/> 

<item android:title="Title" 
    android:id="@+id/id2" 
    android:icon="@drawable/tyre"/> 


<item android:title="Title"> 
    <menu> 
     <item 
      android:title="Title" 
      android:id="@+id/id3" 
      android:icon="@drawable/tyre"/> 
     <item 
      android:title="Title" 
      android:id="@+id/id4" 
      android:icon="@drawable/tyre"/> 
    </menu> 
</item> 

<group android:id="@+id/group_settings_id"> 

    <item android:title="Settings" 
     android:id="@+id/nav_item_settings" 
     android:icon="@drawable/tyre"/> 
    <item android:title="About" 
     android:id="@+id/nav_item_about" 
     android:icon="@drawable/tyre"/> 
    <item android:title="Help" 
     android:id="@+id/nav_item_write_help" 
     android:icon="@drawable/tyre"/> 
    <item android:title="LogOut" 
     android:id="@+id/nav_item_write_logout" 
     android:icon="@drawable/tyre"/> 
</group> 
</menu> 
Смежные вопросы