Home » Android » Get rid of Android navigation drawer translucency

Get rid of Android navigation drawer translucency

Posted by: admin June 15, 2020 Leave a comment

Questions:

In my app, I’m using the navigation drawer from the support library. It is translucent by default, and setting it or its childrens’ background color just adds a translucent version of this color.
This is the drawer and its two children:

 <android.support.v4.widget.DrawerLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black">
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<ListView android:id="@+id/left_drawer_p"
    android:layout_width="500dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="@color/grey"/>
</android.support.v4.widget.DrawerLayout>
How to&Answers:

You want to setScrimColor with zero alpha.

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setScrimColor(Color.parseColor("#00FFFFFF"));

where R.id.drawer_layout is the id of my DrawerLayout

Answer:

I dont really understand your question, but if you are trying to make the navigation drawer transparent then use the following code:

android:background="#60FFFFFF"

Where the ’60’ is about 38% transparency (60 in hex is 96 in decimal, so 96/255 %).

But if your navigation drawer is already transparent I have used the code:

android:background="#FFFFFF"

It works fine and it is not transparent.

Both colours are the HTML colour code for white, a simple google search will find you the code for other colours.