How to set transparency of Navigation drawer backg

2019-07-05 03:03发布

I need to be able to set the background as completely transparent. Seems no one has tried it before . Please help.

If Im correct we need to make framelayout backgrund totally transparent . But no effect taking place on doing it.

Thanks for all your reponses , but none ofthem seems to be working so far.

To clarify further , I need to make the background below the listview to be transparent.

That is, when the drawer is opened completely .There is a partial screen from the below activity that is visible. It shows as blurred greyed out with some text visible. I need that to be perfectly visible.

Do I need to change some themes in activity?

The following is the complete layout xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navDraweLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/headerLayout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/headerBlue"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:padding="10dp" >

    <Button
        android:id="@+id/drawer_btn"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentLeft="true"
        android:background="@color/logoutBtnBlue"
        android:onClick="drawerBtnClicked"
        android:padding="5dp"
        android:textColor="@color/white" />

    <TextView
        android:id="@+id/headerText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:text="PeepApp"
        android:textColor="@color/white"
        android:textSize="25dp" />

    <Button
        android:id="@+id/logout_btn"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:background="@color/logoutBtnBlue"
        android:onClick="logoutBtnClicked"
        android:padding="5dp"
        android:text="Logout"
        android:textColor="@color/white" />
</RelativeLayout>

<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:alpha="1"  
     android:background="@android:color/transparent"
     >

    <FrameLayout
        android:id="@+id/content_frame"
         android:alpha="0.3"  
         android:background="#00000000"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!--
     android:layout_gravity="start" tells DrawerLayout to treat
     this as a sliding drawer on the left side for left-to-right
     languages and on the right side for right-to-left languages.
     The drawer is given a fixed width in dp and extends the full height of
     the container. A solid background is used for contrast
     with the content view.
    -->

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/logoutBtnBlue"
        android:choiceMode="singleChoice"
        android:divider="@android:color/white"
        android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>

1条回答
劫难
2楼-- · 2019-07-05 03:48

Not sure if I understand you, by I'll give it a shot. Let's see. If I am not mistaken, you cannot see the drawer itself. What you see is the ListView inside of it. So in order to set its background transparent all you need to do is set

android:background="@android:color/transparent"

to your ListView XML.

That will make it totally invisible, but if you want transparency with some color you can use accepted answer here to pick the right value.

Hope this helps.

查看更多
登录 后发表回答