0

Ich habe die tablayout-Aktivität mit viewPager für Fragment-Transaktion erstellt.Navigationsleiste Hamburger-Symbol funktioniert nicht

Jetzt ist mein Entwurf geändert und geht Schublade hinzuzufügen. Das Hamburgermenü funktioniert nicht. Beim Streichen von links erscheint es und wenn ich das Symbol drücke, wird es nicht angezeigt. Ich denke, dass es das Layoutproblem sein kann. Aber ich kämpfe, um das Layout zu reparieren.

I versucht, aber wird das ganze Fragment oben bewegend, wenn ich die Position der Schublade zu ändern.

Layout:

<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> 

Antwort

0

separate Datei für Registerkarte Layout alle Registerkarten, dass zu befestigen.

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> 

Dann wird die XML-Layout in der Schublade angebracht ist. In der Schublade habe ich die Navigationsansicht verwendet, um die Liste der Optionen oder Aktionen hinzuzufügen. Die Navigationsansicht app: menu = "@ menu/drawermenu" Dies fügt die Liste der Einträge aus dem Menü ein.

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> 

@ Menü/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>