gpt4 book ai didi

java - Fragment Android 背后的暗淡和模糊背景

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:34 24 4
gpt4 key购买 nike

所以我有一个自定义的“对话框”,它实际上只是框架布局中的一个 fragment 。无论如何,我希望它在显示后模糊和暗化它背后的任何东西。我目前正在使用它,在 onCreateView 中

  // Dim and blur background
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

但是,这并没有模糊或调暗包含 RecyclerView 和 CardView 的其他框架布局,这些元素仍然以完全不透明的方式显示,不知道为什么?

这是一个屏幕截图,您可以看到背景变得模糊,但并非 fragment 后面的所有 View 都变暗

enter image description here

我希望能够在您打开 NavigationDrawer 时实现它的外观,这是同一应用程序中的一个示例,所有内容都正确变暗和模糊。

enter image description here

这是我的 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" />

最佳答案

如评论中所述,FLAG_BLUR_BEHIND 不适用于我使用的框架布局。

我决定只更改父级的前景

// Dim the background
// Where mainFrameLayout is as FrameLayout
mainFrameLayout.getForeground().setAlpha(220);

当您想移除“暗淡”效果时

// Remove dim background color
mainFrameLayout.getForeground().setAlpha(0);

关于java - Fragment Android 背后的暗淡和模糊背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35975989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com