所以我有一个自定义的“对话框”,它实际上只是一个framelayout中的片段。无论如何,我希望它一旦显示出来,它背后的一切都会变得模糊和暗淡。我目前正在使用这个,在onCreateView中
// Dim and blur background
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
然而,这并不是模糊或调暗另一个包含RecyclerView和CardView的framelayout,这些元素仍然以完全不透明的方式显示,不确定为什么?
这是一个截图,你可以看到背景变得模糊了,但并不是所有片段背后的视图都变暗了
当你打开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" />
发布于 2016-05-27 08:49:59
正如评论中所述,FLAG_BLUR_BEHIND
不能与我使用的框架布局一起工作。
我决定只改变父级的前景
// Dim the background
// Where mainFrameLayout is as FrameLayout
mainFrameLayout.getForeground().setAlpha(220);
当您想要移除“暗淡”效果时
// Remove dim background color
mainFrameLayout.getForeground().setAlpha(0);
发布于 2016-03-14 05:29:57
从API14开始,FLAG_BLUR_BEHIND
标志就被弃用了,所以你不应该期望它能工作。
不幸的是,Android在弃用这个标志时并没有提供一个内置的替代方案。但是,已经开发了几种替代解决方案。我建议你看看here描述的500px的模糊库。
这个视图背后的想法是,您调用.setBlurredView(View view)
,而view
是要模糊的BlurringView
下面的视图。然后,由于要模糊的视图已更改,因此每当要重绘模糊时都调用.invalidate()
。请注意,此模糊效果利用了RenderScript
ScriptIntrinsicBlur
效果。
https://stackoverflow.com/questions/35975989
复制相似问题