0

enter image description hereI have two fragment for my current application, In FragmentA I have a search view in Toolbar and on clicking on the search view , I have to show another fragment,FragmentB on top of fragmentA using my framelayout,with transparent view so that the contents in FragmentA can be seen as blurred. The newly opened fragment with transparent background has to show some content in the recycler view . How can we achieve the transparency and the recycler view inside the layout.

Layout code:

<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="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/drawer_layout"
        android:elevation="50dp"
        android:gravity="center"
        android:orientation="vertical">

  
<androidx.appcompat.widget.Toolbar 
   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/palate_survey_bg"
    app:ignore="NamespaceTypo"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


    <androidx.appcompat.widget.SearchView
        android:id="@+id/Advance_search"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@drawable/filter_search_bar_bg_lyt"
        app:iconifiedByDefault="false"
        app:queryHint="Search">

    </androidx.appcompat.widget.SearchView>
    </androidx.appcompat.widget.Toolbar >
        <FrameLayout
            android:id="@+id/search_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar">

        </FrameLayout>

    </LinearLayout>
    
    </androidx.drawerlayout.widget.DrawerLayout
I'm Coder
  • 125
  • 2
  • 13
  • I couldn't even understand what you were trying to do. Maybe a visual representation of what you want to achieve would be better. – Noah Oct 05 '21 at 13:04
  • @Noah- I have added bit more details. – I'm Coder Oct 05 '21 at 13:36
  • @Noah- Any Updates on this? – I'm Coder Oct 06 '21 at 03:15
  • I don't see a reason why you would need another Fragment B to display a RecyclerView. You could have used an Activity, and then inside the Activity, you have a toolbar and a FrameLayout which would then be replaced dynamically by another fragment. The RecyclerView can then be shown inside that Fragment. So one fragment should do. Or is there a specific reason ? – Noah Oct 06 '21 at 11:45

1 Answers1

1

Based on the detailed image you provided. Fragment B is a child fragment of Fragment A. So if you want to show Fragment B when a click event is emitted from the SearchView, you should use Fragment A's FragmentManager. Normally, every fragment has a FragmentManager that can house other fragment views and layouts. To retrieve Fragment A's FragmentManager use this code:

Inside Fragment A:

  Advance_search.setOnClicklistener( v -> {

            getChildFragmentManager()
                  .beginTransaction()
                  .replace(R.id.search_container, new FragmentB())
                  .commit();

}

And then inside Fragment B's onViewCreated() method, you can now inflate the RecyclerView you want into Fragment B's view hierachy.

If you want Fragment B to be transparent, set

<item name="android:windowBackground">@android:color/transparent</item>

Or you can just remove windowBackground entirely.

And set android:backgroud="@android:color/transparent" on Fragment B or just remove it if you have set windowBackround to transparent.

Noah
  • 567
  • 5
  • 21