标签: android-bottomsheetdialog

如何防止 BottomSheetDialogFragment 在导航到另一个片段后消失?

我正在NavigationComponent我的应用程序上使用。

我有一个特定的流程,点击BottomSheetDialogFragment应用程序的按钮后应该导航到另一个片段。但是当弹出该 Fragment 时,我需要导航回上一个BottomSheetDialogFragment.

由于某种原因,该请求BottomSheetDialogFragment被自动驳回。

Frag A : click on a button  
Frag A -> Dialog B : click on a button  
Frag A -> Dialog B -> Frag C : pop Frag C from the stack  
Frag A : Dialog B was automatically dismissed =;/  
Run Code Online (Sandbox Code Playgroud)

如何才能防止这种解雇呢?


问:为什么我需要BottomSheetDialogFragment不解雇?
A:我通过.a监听打开片段的结果LiveData。由于解雇,BottomSheetDialogFragment它永远不会收到结果。

android android-dialog android-dialogfragment android-navigation android-bottomsheetdialog

16
推荐指数
1
解决办法
4061
查看次数

如何在 BottomSheetDialog 上使用视图绑定

我正在尝试在 MainActivity 中创建一个 BottomSheetDialog,但现在我正在使用合成来绑定我的视图。但现在我被如何附加ViewBinding到我的BottomSheetDialog.

这就是我所做的,使用合成材料。

dialog = BottomSheetDialog(this, R.style.BottomDialogStyle)
dialogView = LayoutInflater.from(this).inflate(R.layout.test_dialog, dialog.mainContainer, false)
dialog.setContentView(dialogView)
Run Code Online (Sandbox Code Playgroud)

这就是让我困惑的地方ViewBinding

dialog = BottomSheetDialog(this, R.style.BottomDialogStyle)
binding = TestDialogBinding.inflate(?)
dialog.setContentView(binding.root)
Run Code Online (Sandbox Code Playgroud)

从上面的示例中,我想知道应该用什么填充参数,因为与在活动中我可以只用layoutInflater或在RecyclerView 适配器中填充该参数不同,而在适配器中我不能用

LayoutInflater.from(parent.context), parent, and false

android kotlin android-viewbinding android-bottomsheetdialog

10
推荐指数
1
解决办法
7698
查看次数

如何在 BottomSheetDialogFragment 中正确使用 Jetpack Compose?

例如,我在应用程序中有 MyBottomSheetDialogFragment 和 Compose LazyColumn 代码:

class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return ComposeView(requireContext()).apply {
            setContent {
                Column(horizontalAlignment = Alignment.CenterHorizontally) {
                    Text("Header", color = Color.Black)
                    LazyColumn(
                        Modifier
                            .weight(1f)
                            .fillMaxWidth()) {
                        items(100) {
                            Text("Item $it", Modifier.fillMaxWidth(), Color.Black)
                        }
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并使用以下代码显示它:

MyBottomSheetDialogFragment().show(activity.supportFragmentManager, null)
Run Code Online (Sandbox Code Playgroud)

这就是我们所拥有的:

MyBottomSheetDialogFragment 屏幕图像.jpg

现在,如果向下滚动 LazyColumn 列表,则一切都会正常工作,但如果向上滚动 LazyColumn 列表,则底部工作表对话框将滚动,而不是 LazyColumn 列表。

如何在 BottomSheetDialogFragment 中正确实现 LazyColumn?

当我们使用 XML RecyclerView 列表时,要解决此问题,我们必须使用 NestedScrollView 包装 RecyclerView 列表,如此处所述 …

android-jetpack-compose android-bottomsheetdialog bottomsheetdialogfragment android-jetpack-compose-list lazycolumn

10
推荐指数
1
解决办法
4450
查看次数

Android BottomSheet 灰色抓斗/把手

我在一些流行的应用程序中在BottomSheets 上看到过这种灰色的把手装饰。这是 Google Maps 中 BottomSheet 的屏幕截图。注意BottomSheet 顶部的灰色手柄/夹具。

实现这样的装饰或背景的最佳方法是什么?这个装饰有标准材质或者安卓风格吗?

android bottom-sheet android-bottomsheetdialog

8
推荐指数
1
解决办法
953
查看次数

如何在BottomSheetDialogFragment中设置最大高度?

在此处输入图片说明我有一个BottomSheetDialogFragment,我需要在这个对话框中设置我的高度。我需要,当用户点击按钮时,对话框会出现并填满屏幕的 85%。这该怎么做?

java android bottom-sheet material-components android-bottomsheetdialog

7
推荐指数
3
解决办法
9057
查看次数

Android BottomSheetBehavior 中所有状态的详细解释

大约有六个不同的州BottomSheetBehavior。我没有得到他们的任何适当的解释。

就像我不明白STATE_HIDDEN和之间的区别STATE_COLLAPSED

STATE_SETTLING同样,和 之间有什么区别STATE_DRAGGING

还有什么用STATE_HALF_EXPANDED

android coordinator-layout bottom-sheet android-bottomsheetdialog

7
推荐指数
2
解决办法
7191
查看次数

如何在 BottomSheetDialogFragment 顶部显示另一个片段

有什么办法可以在上面显示片段吗DialogFragment?当我BottomSheetDialogFragment在某些操作后显示时,我需要显示另一个片段(不是对话框片段的类型)而不关闭该对话框,我尝试从对话框中删除暗淡效果并隐藏视图,但这不好,对话框片段是不可见,但是,它的顶部是钢制的,按背面键首先会删除这个不可见的对话框,我需要实现的是正常的后堆栈顺序,就像“正常”片段一样

android fragment dialogfragment android-bottomsheetdialog

7
推荐指数
1
解决办法
1712
查看次数

填充 RecyclerView 后底部工作表对话框跳起来

我遇到了一个奇怪的问题。该应用程序的流程如下:

  1. 触发底部工作表对话框。
  2. 对话片段对服务器进行 api 调用。
  3. 等待响应时显示微调器
  4. 当收到响应时,会填充 Recycler 视图和一些 TextViews。
  5. 一旦 Recycler View 更新,对话框就会从底部跳起来,不再附加到基础上。但是,如果我们滚动 Recycler View,则返回到正常位置。

实际的

当前行为

预期的

预期的

底部工作表对话框相关代码:

        //We have to override this method to ensure that the Bottom Sheet opens in expanded mode.
        @NonNull
        @Override
        public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

            BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

            dialog.setOnShowListener(dialog1 -> {
                BottomSheetDialog d = (BottomSheetDialog) dialog1;

                FrameLayout bottomSheet = d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
                BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
            });

            return dialog;
        }

@Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        views.layoutCartItem.setLayoutManager(new LinearLayoutManager(getContext()));
        views.layoutCartItem.setItemAnimator(new …
Run Code Online (Sandbox Code Playgroud)

android android-bottomsheetdialog

6
推荐指数
1
解决办法
1487
查看次数

Android:快速双击与导航组件相关的任何视图会使应用程序崩溃

我有一个使用导航组件构建的应用程序。我的图表中有一个字段,单击工具栏上的过滤器图标后,该字段会向上滑动底部工作表对话框片段。但是,如果我非常快速地双击工具栏过滤器图标,或者非常快速地单击工具栏过滤器图标和任何与其关联的导航的其他视图,我的应用程序将崩溃并显示以下错误消息:

java.lang.IllegalArgumentException: navigation destination com.th3pl4gu3.locky:id/action_Fragment_Card_to_Fragment_View_Card is unknown to this NavController
Run Code Online (Sandbox Code Playgroud)

下面是我的工具栏过滤器图标的代码示例。

override fun onOptionsItemSelected(item: MenuItem): Boolean {
    return when (item.itemId) {
        R.id.Toolbar_Filter -> {
                findNavController().navigate(CardFragmentDirections.actionFragmentCardToBottomSheetFragmentCardFilter())
            true
        }
        else -> false
    }
}
Run Code Online (Sandbox Code Playgroud)

这是导航架构组件的正常行为吗?

如果没有,您能为我提供修复吗?

android kotlin android-architecture-navigation android-jetpack-navigation android-bottomsheetdialog

6
推荐指数
1
解决办法
3220
查看次数

有时 BottomSheetDialogFragment 在屏幕中央打开,如警报对话框

我有 BottomSheetDialogFragment ,它需要在展开状态下打开,并且应该在向下滑动时跳过折叠状态。

问题是,我有时会遇到意想不到的行为

意外行为

为什么我有时会看到这样的观点?

下面是我的代码,

@Override
    public int getTheme() {
        if (Build.VERSION.SDK_INT > 21) {
            return R.style.BottomSheetDialogTheme;
        } else {
            return super.getTheme();
        }
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

        dialog.setOnShowListener((DialogInterface.OnShowListener) dialog1 -> {
            BottomSheetDialog d = (BottomSheetDialog) dialog1;
            FrameLayout bottomSheet = (FrameLayout) d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
            if (bottomSheet != null) {
                BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
                BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
                BottomSheetBehavior.from(bottomSheet).setFitToContents(true);
                BottomSheetBehavior.from(bottomSheet).setPeekHeight(1000);
            }
        });

        return dialog;
    }
Run Code Online (Sandbox Code Playgroud)

相同的风格/主题是

     <style name="BottomSheetDialogTheme" parent="BaseBottomSheetDialog">
            <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent
            </item>
        </style>
        <!-- set the rounded drawable as …
Run Code Online (Sandbox Code Playgroud)

android android-bottomsheetdialog bottomsheetdialogfragment

6
推荐指数
1
解决办法
1614
查看次数