of course android:layout_marginTop="?attr/actionBarSize" do the job in
<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">
But the problem with drawerlayout is the top of the toolbar. That is why the fading is here. you can remove the attenuation on
mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));
But on some devices, it may look wired.
Decision
When working with Android-studio. We can create a NavigationDrawerActiviity There are 3 files named
activity_main.xml
app_bar_main.xml
nav_header_main.xml
content_main.xml
So, we can skip app_bar_main.xml and we can remove the attenuation.
Step 1
Make the root view of the main activity as Vertical 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 and include content_main.xml in DrawerLayout . and Add AppBarLayout above 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"> <include layout="@layout/content_main" /> <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
add and replace setContentView() with NavigationDrawerActiviity with
setContentView(R.layout.activity_main);
Finally, we have

Kiran Benny Joseph Feb 28 '17 at 11:37 2017-02-28 11:37
source share