activity 底部弹窗的BottomSheetDialog并获取 fragment实例
时间: 2024-03-02 20:53:05 浏览: 37
好的,针对你的问题,可以按照以下步骤实现:
1. 在你的Activity中创建一个BottomSheetDialog对象,代码类似下面这样:
```
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
```
2. 通过BottomSheetDialog对象获取到FragmentTransaction对象,并通过该对象添加你需要显示的Fragment,代码类似下面这样:
```
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, yourFragment);
transaction.commit();
```
其中,R.id.fragment_container为你在Activity布局文件中定义的Fragment容器。
3. 最后,通过BottomSheetDialog对象的getDelegate()方法获取到它的Delegate对象,并通过该对象获取到当前正在显示的Fragment实例,代码类似下面这样:
```
Fragment currentFragment = bottomSheetDialog.getDelegate().getFragmentManager().findFragmentById(R.id.fragment_container);
```
这样就可以获取到当前正在显示的Fragment实例了。
希望这些能够帮到你!
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)