码迷,mamicode.com
首页 > 移动开发 > 详细

android ToolBar与DrawerLayout笔记

时间:2016-06-06 18:47:39      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

通过Android Studio 生成的Nagvition DrawerLayout Activity 自带的布局中的NagvitionView会覆盖ToolBar直接通到statusBar。

但是自己想把NagvationView控制到TooBar下边,从网上找到的答案是把ToolBar从CoordinatorLayout里边移出来,然后

主布局文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:orientation="vertical">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimaryDark"
        />

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

这样就会可以了,但是发现Tool会产生异样的效果如:

技术分享

其实是CoordinatorLayout的属性设置成了android:fitsSystemWindows="true",把这个属性去掉就好了。

app_bar_main布局:

 1 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5      android:fitsSystemWindows="true"    <!--去掉这一句-->    
 6     tools:context="com.mmmmar.box.MainActivity">
 7 
 8     <include layout="@layout/content_main" /><!--你自己的布局-->
 9 
10     <android.support.design.widget.FloatingActionButton
11         android:id="@+id/fab"
12         android:layout_width="wrap_content"
13         android:layout_height="wrap_content"
14         android:layout_gravity="bottom|end"
15         android:layout_margin="@dimen/fab_margin"
16         android:src="@android:drawable/ic_dialog_email" />
17 
18 </android.support.design.widget.CoordinatorLayout>

 

android ToolBar与DrawerLayout笔记

标签:

原文地址:http://www.cnblogs.com/mmmmar/p/5564747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!