【问题标题】:Navigation bar hamburger icon not working导航栏汉堡图标不起作用
【发布时间】:2016-04-18 14:37:42
【问题描述】:

我已经为片段事务创建了带有 viewPager 的 tablayout 活动。

现在我的设计发生了变化,要添加抽屉。因为汉堡菜单不起作用。 从左侧滑动时它会出现,当我按下图标时它不会显示。 我认为这可能是布局问题。但我正在努力修复布局。

我试过了,但是如果我改变抽屉的位置,整个片段都会向上移动。

布局:

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

【问题讨论】:

    标签: android android-layout android-fragments navigation-drawer hamburger-menu


    【解决方案1】:

    选项卡布局的单独文件以附加其中的所有选项卡。

    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附加到抽屉布局中。在抽屉内,我使用导航视图添加选项或操作列表。导航视图 app:menu="@menu/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>
    

    @menu/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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 2021-03-04
      • 2021-07-20
      • 1970-01-01
      • 2021-08-19
      • 2019-10-24
      • 1970-01-01
      相关资源
      最近更新 更多