Bart Burg
Bart Burg

Reputation: 4924

NavigationDrawer remove shadow

What I want to have is a NavigationDrawer that is connected seemless to the main content likee in the design below:

design

Somehow I can't get the shadow from the drawer.

What I tried is this:

drawer.setScrimColor(Color.TRANSPARENT);
drawer.setDrawerShadow(R.drawable.transparent, GravityCompat.START);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    drawer.setElevation(0f);
}

setScrimColor for removing the whole dimming effect but the shadow is still there:

screenshot

My activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

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

    <LinearLayout
        android:layout_width="175dp"
        android:layout_height="match_parent"
        android:background="@color/backgroundColor"
        android:orientation="vertical"
        android:layout_gravity="start"
        android:id="@+id/navigationViews" />

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

Upvotes: 1

Views: 2083

Answers (2)

Abhishek c
Abhishek c

Reputation: 549

Add following codes to your JAVA class.

drawer.setScrimColor(Color.TRANSPARENT); 
drawer.setDrawerElevation(0);

Upvotes: 3

Bart Burg
Bart Burg

Reputation: 4924

The solution was to remove the backgroundcolor from the LinearLayout and move it to the parent Drawerlayout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundColor"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

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

    <LinearLayout
        android:layout_width="175dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_gravity="start"
        android:id="@+id/navigationViews" />

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

Why? I think when the drawerlayout predicts that the drawer has a different background than the mainlayout, it draws a shadow, no matter what setting. I'm not sure, I haven't looked into the source code of Android.

Upvotes: 0

Related Questions