android - FAB 菜单展开时淡入淡出整个屏幕

标签 android screen floating-action-button

我有一个 float 操作按钮菜单,它在点击时展开菜单项。如何实现与下图所示相同的行为?请帮忙。 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>

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

最佳答案

试试这个

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

在您的 Activity 中,您有一个用于展开和关闭 float 菜单的监听器。在那里你应该设置 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>

关于android - FAB 菜单展开时淡入淡出整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31695193/

相关文章:

android - 在 Flutter 应用程序中创建自定义文本选择操作

android - 如何在 Android 上的 iOS 中执行多 View ..stack 之类的操作?

android - BxAndroidBle 无法读取设备,status=22

android - 在 Lollipop Web View 中下载对象 URL?

java - libgdx 无边框全屏

在django中使用fab和curses恢复Mysql数据库

java - 不使用 JFrame 打印屏幕

ios - 如何在 swift 5 中显示模态屏幕?

android - float 操作按钮出现在抽屉导航上方

android - 为什么 Material FAB 在禁用时不改变颜色?