我试图找出如何添加暗淡的背景点击导航抽屉中的FAB菜单

时间:2016-08-09 12:16:15

标签: android android-navigation-drawer floating-action-button

我在导航抽屉里有FAB菜单。我使用android.support.design.widget.FloatingActionButton按钮和onclick,我们以弧形显示四个FAB。我在导航抽屉中有一个容器,它不断更换抽屉中的碎片(抽屉的正常行为)。如何在用户单击FAB菜单按钮时禁用背景。我有点不知道如何完成这个。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


 <FrameLayout
        android:layout_below="@id/toolbar"
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        >
        <RelativeLayout
            android:id="@+id/obstructor"
            android:visibility="invisible"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:alpha="1000"
            android:background="@android:color/black">
</RelativeLayout>

        <android.support.design.widget.FloatingActionButton
        android:id="@+id/home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignBottom="@id/frame_container"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="6dp"
        app:fabSize="normal"
        android:src="@drawable/ic_action_navigation_close_inverted"
        app:backgroundTint="@android:color/holo_red_dark"
        app:rippleColor="#F06292">
</android.support.design.widget.FloatingActionButton>
    </FrameLayout>
   </RelativeLayout>

2 个答案:

答案 0 :(得分:1)

在您的布局中添加此内容,

            android:translationZ="2dp"

它会起作用

<RelativeLayout
            android:id="@+id/obstructor"
            android:visibility="invisible"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0.75"
            android:background="#00000000"
            android:translationZ="2dp"

            />

答案 1 :(得分:0)

您无法通过设置标记来设置它,您需要为FAB按钮的背面添加虚拟布局,并在单击FAB时使其可单击

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


 <FrameLayout
        android:layout_below="@id/toolbar"
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        >
        <RelativeLayout
            android:id="@+id/obstructor"
            android:visibility="invisible"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:alpha="1000"
            android:background="@android:color/black">
</RelativeLayout>
 <LinearLayout
    android:id="@+id/llRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:clickable="false"
    android:orientation="vertical" />
        <android.support.design.widget.FloatingActionButton
        android:id="@+id/home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignBottom="@id/frame_container"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="6dp"
        app:fabSize="normal"
        android:src="@drawable/ic_action_navigation_close_inverted"
        app:backgroundTint="@android:color/holo_red_dark"
        app:rippleColor="#F06292">
</android.support.design.widget.FloatingActionButton>
    </FrameLayout>