通过Android Studio 生成的Nagvition DrawerLayout Activity 自带的布局中的NagvitionView会覆盖ToolBar直接通到statusBar。
但是自己想把NagvationView控制到TooBar下边,从网上找到的答案是把ToolBar从CoordinatorLayout里边移出来,然后
主布局文件:
<?"1.0" encoding="utf-8"?><LinearLayout "http://schemas.android.com/apk/res/android" ="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会产生异样的效果如:
images/loading.gif' data-original="http://images2015.cnblogs.com/blog/933137/201606/933137-20160606181308746-604484913.jpg" />
其实是CoordinatorLayout的属性设置成了android:fitsSystemWindows="true",把这个属性去掉就好了。
app_bar_main布局:
1 <android.support.design.widget.CoordinatorLayout ="http://schemas.android.com/apk/res/android" 2 ="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.FloatingActionButton11 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='/images/loading.gif' data-original="@android:drawable/ic_dialog_email" />17 18 </android.support.design.widget.CoordinatorLayout>
原标题:android ToolBar与DrawerLayout笔记
关键词:Android