在不同片段之间导航时,BottomSheet 不会隐藏

2024-02-17

你好,我有一个bottomsheet使用一些文本视图(作为按钮),按下时它会导航到不同的片段,但问题是当textView被按下并导航到片段仍然底部工作表没有隐藏,最终必须点击屏幕才能隐藏底部工作表,我希望当片段启动时底部工作表将隐藏,这是我遇到的问题的屏幕记录得到link https://drive.google.com/file/d/1KF-aSjSQ3MeQMH-RV6Zkk9ICuDJVluDK/view?usp=sharing

Profile_Fragment.java

 ImageView accountSettings = view.findViewById(R.id.account_Settings);
  accountSettings.setOnClickListener(
                v -> {
                    BottomSheet bottomSheet = new BottomSheet();
                    bottomSheet.show(requireActivity().getSupportFragmentManager(), bottomSheet.getTag());
                }
        );

BottomSheet.java

public class BottomSheet extends BottomSheetDialogFragment {

    public BottomSheet() {
    }

    @Nullable
    @org.jetbrains.annotations.Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.bottom_sheet_profile, container, false);
       

        TextView settingsProfileTextView = view.findViewById(R.id.settings);
        settingsProfileTextView.setOnClickListener(v -> {
            Fragment settings_profile = new Settings_Profile();
            FragmentTransaction transaction = getParentFragmentManager().beginTransaction();
            transaction.add(R.id.fragment_container, settings_profile);
            transaction.addToBackStack(String.valueOf(settings_profile));
            transaction.commit();
          
        });
        TextView editProfileTextView = view.findViewById(R.id.edit_profile);
        editProfileTextView.setOnClickListener(v -> {
            Fragment edit_profile = new Edit_Profile();
            FragmentTransaction transaction = getParentFragmentManager().beginTransaction();
            transaction.add(R.id.fragment_container, edit_profile);
            transaction.addToBackStack(String.valueOf(edit_profile));
            transaction.commit();
        });
        return view;
    }
}

编辑配置文件.java// 当textView被按下时打开的fragment

  @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_edit_profile, container, false);
        profilePhoto = view.findViewById(R.id.circleImageView);
        initImageLoader();
        setProfileImage();
        ImageView imageView = view.findViewById(R.id.backArrow);
        imageView.setOnClickListener(v -> {
            Fragment newCase = new Profile_Fragment();
            assert getFragmentManager() != null;
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.fragment_container, newCase);
            transaction.disallowAddToBackStack();
            transaction.commit();
        });

        return view;
    }

Your BottomSheet是由一个BottomSheetDialogFragment。 它的内部有一个Dialog可以使用dismiss()这最终将驳回BottomSheet.

每当提交片段事务时,将其应用到您的代码中:

    settingsProfileTextView.setOnClickListener(v -> {
        Fragment settings_profile = new Settings_Profile();
        FragmentTransaction transaction = getParentFragmentManager().beginTransaction();
        transaction.add(R.id.fragment_container, settings_profile);
        transaction.addToBackStack(String.valueOf(settings_profile));
        transaction.commit();
        dismiss(); // Dismiss the Bottom sheet
      
    });
    TextView editProfileTextView = view.findViewById(R.id.edit_profile);
    editProfileTextView.setOnClickListener(v -> {
        Fragment edit_profile = new Edit_Profile();
        FragmentTransaction transaction = getParentFragmentManager().beginTransaction();
        transaction.add(R.id.fragment_container, edit_profile);
        transaction.addToBackStack(String.valueOf(edit_profile));
        transaction.commit();
        dismiss(); // Dismiss the Bottom sheet
    });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在不同片段之间导航时,BottomSheet 不会隐藏 的相关文章

随机推荐

  • 如何使用 django 仅渲染 html 的一部分和数据

    我正在使用 ajax 对来自搜索结果的数据进行排序 现在我想知道是否可以只渲染 html 的一部分 以便我可以这样加载 result html nbsp load sort sortid sortid 我正在这样做 但我得到了整个 html
  • 将 printf 移动到不同的行会产生不同的输出? (C)

    在 C 中 当我移动此 printf 行时 printf f n 5 2 对于不同的线路 其输出会发生变化 有任何想法吗 代码如下 include
  • 如何将 apoc.load.csv 与 apoc.create.node 结合使用

    我需要导入 CSV 文件并从每条记录创建一个节点 我使用 APOC 是因为我可以在创建节点时使用 CSV 文件中的列来定义每个节点类型 这不起作用 CALL apoc load csv FILE C Temp Test Test Neo4j
  • 对于 Ajax 请求,省略 p:selectOneMenu 的验证

    我有一个 Jsf 页面 其中包含一个片段
  • winform应用主窗体

    我正在使用 asp net 和 C 开发一个应用程序 它使得使用母版页概念进行开发变得非常容易 现在我正在尝试开发一个Windows窗体应用程序 我真的需要在这里也有一个母版页 有没有诸如主表格之类的东西 谢谢 要在 winform 中模拟
  • 如何在textview中设置unicode以在android中显示表情符号?

    我从服务器获取一些 json 字符串格式的 Unicode 字符串 表情符号图标 我的问题很奇怪 过去两天我一直在努力解决这个问题 当我解析 json 并将所有 Unicode 字符串存储在ArrayList
  • 求树的最大深度

    我知道如何找到二叉树的深度 但我不能概括它适用于任何树 有人可以概述一下用于查找树 不一定是二叉树 深度的伪代码吗 int findDepthOfTree tree int deepest 0 for child of root node
  • 我使用的是哪个版本的 Objective-C?

    我如何知道什么版本Objective C我在用着 我正在使用带有 xCode 的 Mac 我之所以问这个问题是因为我有一本书 Objective C 3 0 并且它说你可以像这样声明一个多维数组 int num 新 int 2 2 当我尝试
  • jquery scrollpane ms ajax updatepanel 回发后不起作用

    我收到了一个网站的新设计 设计者在设计中使用了jquery 我正在将设计实现到 ASP NET Ajax 应用程序中 但我遇到了一个问题 我有一个带有更新面板和菜单的页面 单击菜单项时 用户控件将动态加载到更新面板上的占位符中 这使得页面没
  • MVC 站点地图提供程序和本地化

    今天我发现 对于我的网站 我可以使用从 Github 下载的适用于 MVC3 的 SiteMap 提供程序 因为我的 Web 应用程序是 MVC3 情况如下 我的申请是多语言的 我有一个单独的图书馆 其中包含所有资源 然后这个库被添加到我当
  • 重命名 ASP.NET Core Razor Pages 中的页面/共享目录

    我正在使用 ASP NET Core 5 Razor 页面 通用模板进去Pages Shared 但我需要将其重命名为Pages Foo 如何指示运行时查找文件Pages Foo 我认为这是可能的Startup ConfigureServi
  • OpenShift 上的 WebSocket 不适用于远程客户端

    我有一个无法解决的问题 我使用 socket io 或 WebSockets Node js 库在 openshift 卡带上实现了 Node js WebSockets 服务器 对于其中任何一个 结果都是相同的 使用在同一 openshi
  • 函数和子程序有什么区别?

    函数和子程序有什么区别 有人告诉我函数和子程序之间的区别如下 函数接受参数 在本地工作 不会改变任何值或使用其范围之外的任何值 高内聚 它还返回一些值 子例程直接使用调用者或调用它的代码段的值 并且不返回值 低内聚性 即将某些代码分支到其他
  • 如何在 whoosh 中使用 n 元语法

    我正在尝试使用 n grams 来使用 Whoosh 进行 自动完成式 搜索 不幸的是我有点困惑 我做了一个这样的索引 if not os path exists index os mkdir index ix create in inde
  • 如何使用 Nuxt Auth 模块在 Vuex 中重新获取用户?

    简短的问题 是否可以通过 Nuxt Auth 模块手动更新 Vuex 中的用户数据 为什么我有这个问题 我的问题是这样的 我在用户文档中的 MongoDB 中保存了一些点赞 关注 我的认证是用Nuxt Auth实现的 Nuxt Auth 在
  • Angular UI Router - 允许任何查询字符串参数

    我正在使用 Angular UI Router 这在大多数情况下都运行良好 但是 我遇到了一种情况 我事先不知道查询字符串参数的名称 因此 通常使用 UI 路由器 您会定义如下所示的路由 stateProvider state test u
  • 如何解决超出纳秒范围的问题[重复]

    这个问题在这里已经有答案了 LastLogin LastPurchased 2018 08 21 00 28 04 081677 0001 01 01 00 00 00 2018 08 21 00 28 58 209522 2018 08
  • Javax.net.ssl.SSLHandshakeException:javax.net.ssl.SSLProtocolException:SSL 握手中止:SSL 库失败,通常是协议错误

    我正在尝试在android中运行以下代码 URLConnection l connection null Create connection uzip new UnZipData mContext l url new URL serveru
  • Postgresql WHERE 与age() 函数[重复]

    这个问题在这里已经有答案了 我很确定以前有人问过这个问题 但我正在努力为包含类似数据的表获取正确的语法 id date type report item id 1 2018 11 07 Ver ffentlichung des 9 Mona
  • 在不同片段之间导航时,BottomSheet 不会隐藏

    你好 我有一个bottomsheet使用一些文本视图 作为按钮 按下时它会导航到不同的片段 但问题是当textView被按下并导航到片段仍然底部工作表没有隐藏 最终必须点击屏幕才能隐藏底部工作表 我希望当片段启动时底部工作表将隐藏 这是我遇