我正试图弄清楚如何在导航抽屉中添加FAB菜单的单击上添加暗淡的背景



我在导航抽屉中有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>

添加到你的布局中,

            android:translationZ="2dp"

it will work

<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"
            />

你不能通过设置一个标志来设置它,你需要为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>

最新更新