扩展FAB菜单时淡出整个屏幕

时间:2015-07-29 08:29:25

标签: android screen floating-action-button

我有一个浮动操作按钮菜单,可以在点按时展开菜单项。如何实现与下面照片中显示的相同的行为?请帮忙。 enter image description here

我目前有以下布局语法:

<RelativeLayout
.
. 
/>

    <View
        android:id="@+id/detailsDimView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="#F2FFFFFF"
         android:visibility="gone" />

     <!--main content-->
     <LinearLayout
     .
     .
     />
     <FloatingActionsMenu
     .
     .>
            <!--Floating actions buttons-->
     </FloatingActionsMenu

</RelativeLayout>

但主要内容不会消失。什么似乎是问题?

1 个答案:

答案 0 :(得分:9)

试试这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<!-- Main Content here -- >


<!-- View to show the alpha background -->
<View
    android:id="@+id/shadowView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F2FFFFFF"
    android:visibility="gone" />

<FloatingActionsMenu
    android:id="@+id/floating_menu"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/content"
    android:layout_marginBottom="16dp"
    fab:fab_addButtonColorNormal="@color/accent"
    fab:fab_addButtonColorPressed="@color/accent"
    fab:fab_labelStyle="@style/menu_labels_style"
    fab:fab_labelsPosition="left">

    <!-- Floatingbuttons -->

   </FloatingActionsMenu>
</RelativeLayout>

在您的活动中,您有一个用于展开的监听器并关闭浮动菜单。你应该在那里设置shadowView的可见性。

伪代码侦听器

 @Override
public void onMenuExpanded() {
    mShadowView.setVisibility(View.VISIBLE);
}

@Override
public void onMenuCollapsed() {
    mShadowView.setVisibility(View.GONE);
}

如果要在操作栏/工具栏上方设置shadowView

试试这个

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

 <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primary" />


<!-- Main Content here -- >

<!-- View to show the alpha background -->
<View
    android:id="@+id/shadowView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F2FFFFFF"
    android:visibility="gone" />

<FloatingActionsMenu
    android:id="@+id/floating_menu"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/content"
    android:layout_marginBottom="16dp"
    fab:fab_addButtonColorNormal="@color/accent"
    fab:fab_addButtonColorPressed="@color/accent"
    fab:fab_labelStyle="@style/menu_labels_style"
    fab:fab_labelsPosition="left">

    <!-- Floatingbuttons -->

   </FloatingActionsMenu>
</RelativeLayout>