I 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
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:
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
Or you can just remove
windowBackground
entirely.And set
android:backgroud="@android:color/transparent"
on Fragment B or just remove it if you have setwindowBackround
to transparent.