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