相关疑难解决方法(0)

add(),replace()和addToBackStack()之间的区别

调用这些方法的主要区别是什么:

fragmentTransaction.addToBackStack(name);
fragmentTransaction.replace(containerViewId, fragment, tag);
fragmentTransaction.add(containerViewId, fragment, tag);
Run Code Online (Sandbox Code Playgroud)

替换已存在的片段,将片段添加到活动状态,并向后台堆栈添加活动是什么意思?

其次,有findFragmentByTag(),这是否搜索由add()/ replace()方法或addToBackStack()方法添加的标记?

android android-fragments

277
推荐指数
7
解决办法
14万
查看次数

add()和replace()与Fragment的生命周期之间的区别

我的程序有6个片段:Fragment1,Fragment2,....-> Fragment6.

我使用add()和replace()语句在片段之间切换并跟踪它们的生命周期.

Fragment1 添加 Fragment2 添加 Fragment3 添加 Fragment4 添加 Fragment5 替换 Fragment6

log-cat显示了它们的生命周期(我在onCreate,onCreateView,onDestroyView,onDestroy中有一些printf-points用于跟踪)


标签 __ _ __ _ __ _ __ _ __ 文字

Fragment1_ _ __ _ ___ _onCreate

Fragment1_ _ __ _ ___ _onCreateView

Fragment1_ _ __ _ ___ _add Fragment2

Fragment2_ _ __ _ ___ _onCreate

Fragment2_ _ __ _ ___ _onCreateView

Fragment2_ _ __ _ ___ _add Fragment3

Fragment3_ _ __ _ ___ _onCreate

Fragment3_ _ __ _ ___ _onCreateView

Fragment3_ _ __ _ …

android android-fragments fragment-lifecycle

19
推荐指数
2
解决办法
2万
查看次数

Fragment的add()和replace()方法的基本区别

如何Fragment替换和添加方法的工作方式不同,是否有任何现实生活场景我们需要这些方法用于特定目的.

android android-fragments

11
推荐指数
1
解决办法
2万
查看次数

如何允许BottomSheetDialog的外部触摸?

我正在BottomSheetDialogFragment满足我的要求是创建底部菜单,如果我在片段区域外单击,则不应取消对话框并应保留。

问题: 片段外的事件应传播到较低的片段视图/片段。

我已经在下面尝试过(不适用于BottomDialogFragment): Allow external touch for DialogFragment

要停止对话框中取消我尝试下面(我称之为setCancelable(boolean)onStart()BottomDialogFragment的):

@Override
    public void setCancelable(boolean cancelable) {
        super.setCancelable(cancelable);

        BottomSheetDialog dialog = (BottomSheetDialog) getDialog();
        dialog.setCanceledOnTouchOutside(cancelable);

        View bottomSheetView = dialog.getWindow().getDecorView().findViewById(R.id.design_bottom_sheet);
        BottomSheetBehavior.from(bottomSheetView).setHideable(cancelable);
    }
Run Code Online (Sandbox Code Playgroud)

参考

编辑:发现它很难,没有其他方法然后使用坐标布局。BottomSheetDialog 的最佳解决方案是here

  • 这个解决方案解决了这个问题,但又带来了一个问题。即所有其他应用程序事件都没有导航所有 actionMode 事件。
  • 这是我对问题的最佳解决方案

android fragment bottom-sheet

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