0

在此处输入图像描述我当前的应用程序有两个片段,FragmentA在工具栏中有一个搜索视图并单击搜索视图时,我必须显示另一个片段,FragmentBfragmentA 使用我的框架布局之上,具有透明视图,以便FragmentA可以看到其中的内容一样模糊。新打开的具有透明背景的片段必须在回收站视图中显示一些内容。我们如何实现布局内部的透明度和回收器视图。

布局代码:

<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
4

1 回答 1

1

根据您提供的详细图像。Fragment B 是 Fragment A 的子 Fragment。因此,如果要在 SearchView 发出点击事件时显示 Fragment B,则应使用 Fragment A 的FragmentManager。通常,每个片段都有一个 FragmentManager 可以容纳其他片段视图和布局。要检索 Fragment A 的 FragmentManager,请使用以下代码:

内部片段 A:

  Advance_search.setOnClicklistener( v -> {

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

}

然后在 Fragment B 的 onViewCreated() 方法中,您现在可以将所需的 RecyclerView 膨胀到 Fragment B 的视图层次结构中。

如果您希望 Fragment B 透明,请设置

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

或者您可以完全删除windowBackground

并设置android:backgroud="@android:color/transparent"在片段 B 上,或者如果您设置windowBackround为透明,则将其删除。

于 2021-10-06T11:55:05.760 回答