如何使用底部表对话框Android实现边缘到边缘
我完全基于沉浸式模式有一个Android应用程序。我已经设法在整个应用程序上进行边缘到边缘,但是当我打开一个底部纸对话框时,屏幕上的peek高度为90%,滚动浏览量可容纳长表格。但是,当我打开底部纸时,视图底部有一个空白空间,这正是系统导航栏的大小。有没有办法删除该空间并使底部纸延伸到屏幕的底部?
编辑:添加了我的底部表对话框类别的示例
class MyBottomSheetDialog
constructor(val ctx: Context, val height: Int) :
BaseDialog(ctx) {
...
override fun onStart() {
super.onStart()
binding.root.layoutParams.height = height
binding.root.requestLayout()
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
window?.let {
WindowCompat.setDecorFitsSystemWindows(
it,false
)
}
findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows = false
findViewById<View>(com.google.android.material.R.id.coordinator)?.fitsSystemWindows = false
}
...
}
- base类是 -
open class BaseDialog
constructor(
private val dialogContext: Context) : BottomSheetDialog(dialogContext, style) {
override fun onStart() {
super.onStart()
hideNavigation()
}
private fun hideNavigation() {
window?.apply {
val uiOptions: Int = decorView.systemUiVisibility
val newUiOptions = uiOptions or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_FULLSCREEN
decorView.systemUiVisibility = newUiOptions
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
setGravity(Gravity.BOTTOM)
}
}
}
I have an android application entirely based on immersive mode. I have managed to go edge-to-edge for the entire application but when I open a bottom sheet dialog with peek height of uptop 90% of the screen and a scrollview to accomodate a long form. However, when I open the bottom sheet, there is a blank space at the bottom of the view which is exactly the size of the system navigation bar. Is there a way to remove that space and have the bottom sheet extend right upto the bottom of the screen?
Here's a snapshot of the bottom sheet fully expanded
EDIT: Added Example of My bottomsheet dialog class-
class MyBottomSheetDialog
constructor(val ctx: Context, val height: Int) :
BaseDialog(ctx) {
...
override fun onStart() {
super.onStart()
binding.root.layoutParams.height = height
binding.root.requestLayout()
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
window?.let {
WindowCompat.setDecorFitsSystemWindows(
it,false
)
}
findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows = false
findViewById<View>(com.google.android.material.R.id.coordinator)?.fitsSystemWindows = false
}
...
}
And The base class is-
open class BaseDialog
constructor(
private val dialogContext: Context) : BottomSheetDialog(dialogContext, style) {
override fun onStart() {
super.onStart()
hideNavigation()
}
private fun hideNavigation() {
window?.apply {
val uiOptions: Int = decorView.systemUiVisibility
val newUiOptions = uiOptions or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_FULLSCREEN
decorView.systemUiVisibility = newUiOptions
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
setGravity(Gravity.BOTTOM)
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在主题中的底部表面范围中
:
在样式中:
In your bottomSheetFragment
in themes:
in styles:
根据材料底部表doc :
在主题文件中。另请参见 Google Edge到Edge训练页面。
According to the Material Bottom Sheet doc:
in your theme file. See also Google edge to edge training page.