1

I have created a recycler view containing a list of items , for example options like Home, contacts profile with the help of Adapter in my FragmentA class. so currently on clicking each of the items in recycler view, I'm opening a fragment above the Fragment A. so once the fragment is opened, I have to show a blur background below the opened Fragment, so that the items in FragmentA can be slightly visible and once the user clicks the blur view , they have to close the opened fragment also. How can we blur the view and close the Fragment by clicking on the blurview??

sample code for fragmentA layout, where I'm adding the newly opened fragment into the filter_pop_up_frame_lyt which shows above the Main Fragment A

<?xml version="1.0" encoding="utf-8"?>

<androidx.drawerlayout.widget.DrawerLayout 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"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">


    <LinearLayout
        android:id="@+id/dot_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/drawer_layout"
        android:layout_centerInParent="true"
        android:elevation="50dp"
        android:gravity="center">


    <androidx.core.widget.NestedScrollView
        android:id="@+id/scrollView_lyt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/tastry_btn_txt"
        android:isScrollContainer="false"
        android:visibility="visible">


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

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

            <LinearLayout
                android:id="@+id/filter_container_lyt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/toolbar"
                android:layout_marginTop="2dp"
                android:background="#495471"
                android:gravity="center_vertical"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/filter_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/toolbar"
                    android:layout_margin="15dp"
                    android:layout_marginTop="10dp"
                    android:gravity="center_vertical"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:src="@drawable/filter">

                    </ImageView>

                    <TextView
                        android:id="@+id/filter_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:fontFamily="sans-serif-medium"
                        android:text="Filter By"
                        android:textColor="@color/white"
                        android:textSize="22dp"
                        android:textStyle="normal" />

                </LinearLayout>

                <androidx.coordinatorlayout.widget.CoordinatorLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
                    android:layout_marginLeft="3dp">

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/recycler_view_filter_category"
                        android:layout_width="wrap_content"
                        app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
                        android:layout_height="wrap_content" />
                </androidx.coordinatorlayout.widget.CoordinatorLayout>
            </LinearLayout>

            <FrameLayout
                android:id="@+id/filter_pop_up_frame_lyt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/filter_container_lyt"
                android:elevation="5dp">


            </FrameLayout>


    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/palate_survey_bg"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/header"
        app:itemIconSize="20dp"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:menu="@menu/drawermenu" />


</androidx.drawerlayout.widget.DrawerLayout>

SampleCode for the Fragment to be opened Above the MainFragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linear_layout_root_price_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <!--    android:background="@drawable/filter_bg_round_corner"-->

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/filter_bg_round_corner"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/progress_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"

            android:orientation="vertical">

            <com.google.android.material.slider.RangeSlider
                android:id="@+id/filter_price_ranger_Slider"
                style="@style/Theme.TastrySampleApp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:progressDrawable="@drawable/progress_layout_bg"
                android:stepSize="1"
                android:theme="@style/Theme.TastrySampleApp"
                android:valueFrom="0.0"
                android:valueTo="100.0"
                app:labelBehavior="gone"
                app:thumbColor="#01b0c3"
                app:tickVisible="false"
                app:values="@array/initial_slider_values" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/onStartTrackingTouch"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="9dp"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:text="$0"
                    android:textColor="@color/black"
                    android:textSize="16sp">

                </TextView>

                <TextView
                    android:id="@+id/onStopTrackingTouch"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:text="$100+"
                    android:textColor="@color/black"
                    android:textSize="16sp">

                </TextView>
            </RelativeLayout>
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_margin="10dp"
            android:layout_marginTop="20dp"
            android:background="#99a3bc">

        </View>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:gravity="right"
            android:orientation="horizontal"
            android:padding="14dp">

            <TextView
                android:id="@+id/filter_price_wine_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:gravity="center"
                android:maxLines="1"
                android:text="1234"
                android:textColor="@color/black"
                android:textSize="20sp"
                android:textStyle="bold"
                android:visibility="gone">

            </TextView>

            <TextView
                android:id="@+id/filter_price_wine_txt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_weight="0"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="Wines"
                android:textColor="@color/black"
                android:textSize="20sp"
                android:textStyle="bold"
                android:visibility="gone">

            </TextView>


            <View
                android:layout_width="0dp"
                android:layout_height="10dp"
                android:layout_gravity="center"
                android:layout_weight="1" />

            <LinearLayout
                android:id="@+id/filter_price_root_clear_lyt"
                android:layout_width="110dp"
                android:layout_height="35dp"
                android:layout_gravity="center"
                android:layout_marginLeft="50dp"
                android:layout_toLeftOf="@+id/filter_price_Apply"
                android:background="@drawable/filter_clear_bg"
                android:gravity="center"
                android:visibility="gone">

                <ImageView
                    android:id="@+id/close_filter_price"
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="2dp"
                    android:src="@drawable/close_white">

                </ImageView>

                <TextView
                    android:id="@+id/clear_price_filter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="6dp"
                    android:layout_marginTop="3dp"
                    android:layout_toRightOf="@id/close_filter_price"
                    android:text="Clear All"
                    android:textStyle="bold"
                    android:textColor="#f2faff">

                </TextView>

                <TextView
                    android:id="@+id/price_clear_count"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginTop="3dp"
                    android:layout_toRightOf="@id/clear_price_filter"
                    android:textStyle="bold"
                    android:textColor="#f2faff">

                </TextView>

            </LinearLayout>

            <com.google.android.material.button.MaterialButton
                android:id="@+id/filter_price_Apply"
                android:layout_width="wrap_content"
                android:layout_height="35dp"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:background="@drawable/filter_apply_bg"
                android:gravity="center"
                android:text="Apply"
                android:textAllCaps="false"
                android:textColor="#f2faff"
                android:textSize="12sp"
                android:visibility="gone">

            </com.google.android.material.button.MaterialButton>

        </LinearLayout>
    </LinearLayout>

</LinearLayout>
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
I'm Coder
  • 125
  • 2
  • 13
  • 1
    The only native solution available is in Android 12 with `RenderEffect` https://developer.android.com/about/versions/12/features#rendereffect all other api versions will need a library or custom implementation – tyczj Sep 30 '21 at 13:22
  • @tyczj - is there any specific library which satisfy my requirement. I have to run this on all api versions. – I'm Coder Sep 30 '21 at 13:38
  • Any updates regarding this?? – I'm Coder Oct 01 '21 at 04:30
  • Try this [Android Blur View](https://stackoverflow.com/questions/31808955/android-blur-view-blur-background-behind-the-view) – Noah Oct 06 '21 at 12:10

0 Answers0