我正在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
我正在尝试在 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
例如,我在应用程序中有 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
我在一些流行的应用程序中在BottomSheets 上看到过这种灰色的把手装饰。这是 Google Maps 中 BottomSheet 的屏幕截图。注意BottomSheet 顶部的灰色手柄/夹具。
实现这样的装饰或背景的最佳方法是什么?这个装饰有标准材质或者安卓风格吗?
java android bottom-sheet material-components android-bottomsheetdialog
大约有六个不同的州BottomSheetBehavior
。我没有得到他们的任何适当的解释。
就像我不明白STATE_HIDDEN
和之间的区别STATE_COLLAPSED
?
STATE_SETTLING
同样,和 之间有什么区别STATE_DRAGGING
?
还有什么用STATE_HALF_EXPANDED
?
android coordinator-layout bottom-sheet android-bottomsheetdialog
有什么办法可以在上面显示片段吗DialogFragment
?当我BottomSheetDialogFragment
在某些操作后显示时,我需要显示另一个片段(不是对话框片段的类型)而不关闭该对话框,我尝试从对话框中删除暗淡效果并隐藏视图,但这不好,对话框片段是不可见,但是,它的顶部是钢制的,按背面键首先会删除这个不可见的对话框,我需要实现的是正常的后堆栈顺序,就像“正常”片段一样
我遇到了一个奇怪的问题。该应用程序的流程如下:
实际的
预期的
底部工作表对话框相关代码:
//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) 我有一个使用导航组件构建的应用程序。我的图表中有一个字段,单击工具栏上的过滤器图标后,该字段会向上滑动底部工作表对话框片段。但是,如果我非常快速地双击工具栏过滤器图标,或者非常快速地单击工具栏过滤器图标和任何与其关联的导航的其他视图,我的应用程序将崩溃并显示以下错误消息:
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
我有 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 ×9
bottom-sheet ×3
kotlin ×2
android-architecture-navigation ×1
android-jetpack-compose-list ×1
fragment ×1
java ×1
lazycolumn ×1