【问题标题】:Toolbar was hidden behind the navigation drawer工具栏隐藏在导航抽屉后面
【发布时间】:2015-04-09 14:36:16
【问题描述】:
    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            android:minHeight="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:background="@color/main_color"
            >
        </android.support.v7.widget.Toolbar>


        <FrameLayout
            android:id="@+id/left_drawer"
            android:layout_width="300dp"
            android:layout_height="match_parent"
            android:layout_gravity="left" />
        <FrameLayout
            android:id="@+id/view_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />


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

我正在尝试配置以下组件

工具栏(Appcompat v7 版本)

导航抽屉

但是我的工具栏应该像 google keep 一样放在导航栏后面?

【问题讨论】:

    标签: android navigationbar google-keep


    【解决方案1】:

    将您的Drawer 放在主要的View 下方:

    <android.support.v4.widget.DrawerLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
         <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
        <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="wrap_content"
                app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                android:minHeight="?attr/actionBarSize"
                android:layout_width="match_parent"
                android:background="@color/main_color"
                >
            </android.support.v7.widget.Toolbar>
    
               <FrameLayout
                android:id="@+id/view_main"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <FrameLayout
                android:id="@+id/left_drawer"
                android:layout_width="300dp"
                android:layout_height="match_parent"
                android:layout_gravity="left" />
    
    
    
        </LinearLayout>
    </android.support.v4.widget.DrawerLayout>
    

    文件中的低位意味着 Z 轴的高位。

    【讨论】:

      【解决方案2】:

      这是最新的解决方案

      <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          tools:openDrawer="start">
      
          <android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
      
      android:layout_height="@dimen/abc_action_bar_default_height_material"
              android:background="?attr/colorPrimary"
              android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
      
      </android.support.design.widget.AppBarLayout>
      
      <android.support.v4.widget.DrawerLayout
          android:id="@+id/drawer_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
         <!--content_main is my layout you can design your own-->
          <include layout="@layout/content_main" />
      
          <FrameLayout
              android:id="@+id/content"
              layout="@layout/content_main"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
      
          <!-- The navigation drawer -->
          <android.support.design.widget.NavigationView
              android:id="@+id/nav_view"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_gravity="start"
              app:menu="@menu/activity_main_drawer" />
      
      </android.support.v4.widget.DrawerLayout>
      
      
      </LinearLayout>
      

      希望对你有帮助

      【讨论】:

        【解决方案3】:

        我找到了答案

        <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
            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"
            android:orientation="vertical">
        
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
        
                <android.support.v7.widget.Toolbar
        
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/main_color"
                    android:minHeight="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
        
                <FrameLayout
                    android:id="@+id/view_main"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true" />
            </LinearLayout>
        
               <FrameLayout
                android:id="@+id/left_drawer"
                android:layout_width="300dp"
                android:layout_height="match_parent"
                android:layout_gravity="left"
                android:fitsSystemWindows="true" />
        
        
        </android.support.v4.widget.DrawerLayout>
        

        【讨论】:

          猜你喜欢
          • 2016-03-26
          • 2014-12-23
          • 1970-01-01
          • 1970-01-01
          • 2020-05-25
          • 1970-01-01
          • 2015-02-26
          • 2015-01-15
          • 1970-01-01
          相关资源
          最近更新 更多