抽屉式导航栏下面的材料设计工具栏 [英] Navigation Drawer below Tool bar in Material Design

查看:155
本文介绍了抽屉式导航栏下面的材料设计工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的抽屉,从左侧工具栏的下方打开。但是,根据材料设计方面,这不是很好。但我仍想这样做。

在这里,我已经改变了我的XML文件。

---相对布局

-----工具栏

-----抽屉

-------容器

-------抽屉列表

这是我的XML文件。在打开时我的应用程序崩溃。我不知道我犯了一个错误和XML不显示任何错误。

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent><包括
    机器人:ID =@ + ID /工具栏
    布局=@布局/工具栏/>< android.support.v4.widget.DrawerLayout
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:ID =@ + ID / drawer_layout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>    <的FrameLayout
        机器人:ID =@ + ID / container_body
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =0dp
        机器人:layout_weight =1/>    <片段
        机器人:ID =@ + ID / fragment_navigation_drawer
        机器人:名字=com.myApp.activity.FragmentDrawer
        机器人:layout_width =@扪/ nav_drawer_width
        机器人:layout_height =match_parent
        机器人:layout_gravity =开始
        应用:布局=@布局/ fragment_navigation_drawer
        工具:布局=@布局/ fragment_navigation_drawer/>< /android.support.v4.widget.DrawerLayout>< / RelativeLayout的>


解决方案

下面是材料设计的最新解决方案
    
    

 < android.support.design.widget.AppBarLayout
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    工具:openDrawer =开始>    < android.support.v7.widget.Toolbar
        机器人:ID =@ + ID /工具栏
        机器人:layout_width =match_parent机器人:layout_height =@扪/ abc_action_bar_default_height_material
        机器人:ATTR / colorPrimary背景=
        机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar/>< /android.support.design.widget.AppBarLayout>< android.support.v4.widget.DrawerLayout
    机器人:ID =@ + ID / drawer_layout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>   <! - content_main是我的布局,你可以设计自己的 - >
    <包括布局=@布局/ content_main/>    <的FrameLayout
        机器人:ID =@ + ID /内容
        布局=@布局/ content_main
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent/>    <! - 导航抽屉 - >
    < android.support.design.widget.NavigationView
        机器人:ID =@ + ID / nav_view
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =match_parent
        机器人:layout_gravity =开始
        应用:菜单=@菜单/ activity_main_drawer/>< /android.support.v4.widget.DrawerLayout>
< / LinearLayout中>

希望它能帮助

I want my drawer to open from the left below the tool bar. But, according to Material Design aspects that's not good. But still I want to do that.

Here I have changed my XML file.
---Relative Layout
-----Tool bar
-----Drawer
-------container
-------drawer List

here is my XML file. My app crashes when it opens. I don't know where I made a mistake and XML doesn't show any errors.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar" />

<android.support.v4.widget.DrawerLayout
    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">

    <FrameLayout
        android:id="@+id/container_body"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.myApp.activity.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />

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

</RelativeLayout>

解决方案

Here is the latest solution for material design

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

Hope it helps

这篇关于抽屉式导航栏下面的材料设计工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆