当FAB菜单展开时,整个屏幕变暗

3
我有一个悬浮操作按钮菜单,当被点击时扩展菜单项。我如何实现与下面照片显示的相同行为?请帮忙。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>

但主要内容没有消失。看起来是什么问题呢?


更改顺序,先主要内容再是影子视图。 - eddykordo
没错,这对我有效,但希望它包括操作栏。我不想更改我的操作栏代码。 - MetaSnarf
1个回答

12

试试这个

<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设置在actionbar/toolbar之上,请尝试以下操作。
    <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>

动作栏怎么样? - MetaSnarf
在我的情况下,我使用工具栏,因此您可以将工具栏添加到您的布局中,在阴影视图上方添加工具栏。 - eddykordo
所有的代码都能正常运行,但为了更好地显示背景,请使用以下颜色代码:#CCFFFFFF。 - aarti Ladva

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接