【发布时间】:2016-03-13 21:17:40
【问题描述】:
所以我有一个自定义的“对话框”,它实际上只是框架布局中的一个片段。 无论如何,我希望它一旦显示就模糊和变暗它背后的任何东西。 我目前正在使用这个,在 onCreateView
// Dim and blur background
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
但是,这并没有使包含 RecyclerView 和 CardView 的其他框架布局模糊或变暗,这些元素仍然以完全不透明的方式显示,不知道为什么?
这是一个截图,您可以看到背景变得模糊,但并非片段后面的所有视图都变暗
我希望能够实现 NavigationDrawer 在您打开它时的外观,这是同一个应用程序中的一个示例,所有内容都被正确调暗和模糊。
这是我的 XML 文件,以防万一,
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".controllers.MainActivity"
android:id="@+id/app_bar_main_layout">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
// This is the framelayout for a fragment
// The fragment contains a RecyclerView and a CardView
// This is what I would like to be dimmed.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame_layout_container"
android:background="@color/colorCardDisplayBackground"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
// This is my custom "Dialog" fragment
<FrameLayout
android:elevation="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/card_fragment_container">
<ImageButton
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_gravity="bottom|end"
android:layout_marginRight="15dp"
android:background="@drawable/round_button_background"
android:elevation="8dp"
android:src="@drawable/ic_done_white_24dp"
android:scaleType="center"
android:visibility="gone"
android:id="@+id/final_confirm_card_button"/>
</FrameLayout>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:id="@+id/mainFab"
android:layout_height="wrap_content"
fab:fab_icon="@drawable/ic_add_white_48dp"
fab:fab_colorNormal="@color/colorAccent"
fab:fab_colorPressed="@color/colorAccentLight"
android:layout_gravity="bottom|end" />
【问题讨论】:
-
@DanielNugent,这不是一个可能的解决方案,实际上也不能解决这个问题。
-
事实上,一个 DialogFragment 是 Android 框架提供的,以便轻松地完成您想要做的事情。您可以在 DialogFragment 中实现与在任何其他 Fragment 中相同的功能,并且背景将以标准方式变暗和模糊。如果您的项目架构阻止您使用 DialogFragment,那就这样吧,但如果您可以使用它,它将解决您的问题。
标签: java android android-studio