【问题标题】:How to set transparency of Navigation drawer background?如何设置导航抽屉背景的透明度?
【发布时间】:2014-05-22 13:32:16
【问题描述】:

我需要能够将背景设置为完全透明。似乎以前没有人尝试过。请帮忙。

如果我是正确的,我们需要让 framelayout backgrund 完全透明。但这样做没有任何影响。

感谢您的所有回复,但到目前为止似乎没有一个有效。

为了进一步澄清,我需要使列表视图下方的背景透明。

也就是说,当抽屉完全打开时。下面的活动有一个部分屏幕是可见的。它显示为模糊的灰色,并显示一些文本。我需要它完全可见。

我需要更改活动中的一些主题吗?

以下是完整的布局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>

【问题讨论】:

  • 如果您希望导航抽屉的滑入滑出是透明的,您必须使您的 ListView 透明。
  • 为了澄清,有人在 SO - here 上询问和回答。干杯!

标签: android navigation-drawer


【解决方案1】:

不确定我是否理解你,我会试一试。让我们来看看。如果我没记错的话,你看不到抽屉本身。你看到的是里面的ListView。所以为了设置它的背景透明,你需要做的就是设置

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

到您的 ListView XML。

这将使它完全不可见,但如果你想要一些颜色的透明度,你可以使用接受的答案 here 来选择正确的值。

希望这会有所帮助。

【讨论】:

  • 谢谢,但我需要使列表视图下方的屏幕透明。我已经编辑了我的问题以进一步澄清。
猜你喜欢
  • 2013-06-10
  • 2014-03-14
  • 2023-03-02
  • 2019-09-07
  • 2020-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多