当然android:layout_marginTop="?attr/actionBarSize"
做这份工作
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
但问题是抽屉布局位于工具栏的顶部。这就是这里褪色的原因。
你可以通过以下方式消除褪色
mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));
但在某些设备上它可能看起来是有线的。
Solution
使用 Android studio 时。我们可以创造NavigationDrawerActiviity
有3个文件名为
活动主文件
app_bar_main.xml
nav_header_main.xml
内容_main.xml
所以我们可以跳过app_bar_main.xml
我们可以消除褪色。
Step 1
使活动的根视图主要为垂直LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:orientation="vertical"
android:fitsSystemWindows="true"
tools:context="com.example.MainActivity">
</LinearLayout>
In activity_main.xml
add DrawerLayout
并包括content_main.xml
in DrawerLayout
。并添加AppBarLayout
上面的DrawerLayout
.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:orientation="vertical"
tools:context="com.qproinnovations.schoolmanagement.activity.HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" >
</android.support.v7.widget.Toolbar>
</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"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<!-- drawer view -->
<include layout="@layout/content_main" />
<!-- drawer content -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Step 2
添加和替换setContentView()
导航抽屉活动
setContentView(R.layout.activity_main);
最后我们有