java - 点击 FAB 上的 Alpha 背景

标签 java android android-background floating-action-button

我正在使用库 https://github.com/futuresimple/android-floating-action-button创建效果很好的精美按钮。我尝试了几个库,但没有一个使用 fab(或 keep、inbox 等 Google 应用程序)中大多数应用程序中使用的效果,当单击 fab 时,整个应用程序的背景变成半透明的白色或黑色,这取决于。我找不到任何方法来做到这一点。是否有可能有一个例子或类似的东西来做这种效果?你可以在这张图片中看到我的意思: enter image description here

半黑背景

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/semi_white_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_semi_transparent"
        android:visibility="gone" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/listFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/content_frame"
        android:visibility="gone" >

        <TextView
            android:id="@+id/status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/cabinet_color"
            android:fontFamily="sans-serif"
            android:gravity="center_vertical"
            android:paddingBottom="8dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:paddingTop="8dp"
            android:textColor="#fff"
            android:textSize="17sp"
            android:visibility="gone" />

        <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />

        <LinearLayout
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/emptyImage"
                android:layout_width="96dp"
                android:layout_height="96dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="16dp"
                android:scaleType="fitXY"
                android:src="?empty_image" />

            <TextView
                android:id="@+id/emptyText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:fontFamily="sans-serif-light"
                android:gravity="center"
                android:lineSpacingMultiplier="1.4"
                android:paddingBottom="16dp"
                android:text="@string/no_files"
                android:textColor="?empty_text"
                android:textSize="22sp" />
        </LinearLayout>
    </RelativeLayout>

    <ProgressBar
        android:id="@android:id/progress"
        style="?android:progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminateOnly="true" />

</RelativeLayout>

这是我的 layout.xml,但似乎根本无法正常工作。似乎没有与整个 View 重叠,只是为它想要的颜色着色。

最佳答案

我发现这是我认为最简单的解决方案,而且效果很好:

fam.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
        @Override
        public void onMenuExpanded() {
            dimmedBackground.setVisibility(View.VISIBLE);
        }

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

关于java - 点击 FAB 上的 Alpha 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29342920/

相关文章:

android - 如何在具有多个 Activity 的 Android 应用程序上使用 Pusher?

android - 配置更改后或启动这些操作的 Activity 被破坏后,SQLite CRUD 操作的预期行为是什么?

java - 如何重新附加到现有的 Java EE session

java - 为什么 MessageDigest 对同一个字符串返回不同的答案?

java - 如何在spring mvc中设置响应头

java - 为什么我不能声明一个数组,然后以这种方式赋值?

Android native 运行时无法加载符号,即使它们实际上在加载的 .so 文件中找到

java - Android 库中的 string.xml

android - 激活电池优化时如何执行后台服务

android - 您可以在您的 Android 应用程序中同时运行两个后台服务吗?