android - 在 Kotlin 中显示对话框时如何隐藏片段中的底部导航栏?
问题描述
显示对话框时,我很难隐藏底部导航栏。我希望它不会出现,因为应用程序以全屏模式显示。
这是构建对话框的类:
class CreateNewFolderDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let {
// Use the Builder class for convenient dialog construction
//val builder = AlertDialog.Builder(it, R.style.AppBaseTheme)
val builder = AlertDialog.Builder(it)
val inflater = requireActivity().layoutInflater;
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.create_new_folder_dialog, null))
// Add action buttons
.setPositiveButton("OK",
DialogInterface.OnClickListener { dialog, id ->
// create folder ...
})
.setNegativeButton("Cancel",
DialogInterface.OnClickListener { dialog, id ->
getDialog()?.cancel()
})
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
}
这是它在另一个片段中的调用:
fun createNewFolderDialog() {
val supportFragmentManager: FragmentManager = (activity as AppCompatActivity).supportFragmentManager
val newFragment = CreateNewFolderDialogFragment()
newFragment.show(supportFragmentManager, "newfolder")
}
这是我在显示对话框时得到的屏幕截图。如您所见,显示了底部导航栏。我想防止这种情况出现,永远。
解决方案
您可以通过以下代码隐藏系统导航栏:
window.decorView.apply {
// Hides the navigation bar.
systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
隐藏系统导航栏的限制很少,您可以在下面的链接中查看。 源代码- Android 文档
您可以使用类的window
对象,并可以在您的类中DialogFragment
设置上述标志的方法,如下面的代码:CreateNewFolderDialogFragment
onStart
override fun onStart() {
super.onStart()
dialog?.window?.decorView?.apply {
// Hide both the navigation bar
systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
}
推荐阅读
- jhipster - 我可以使用 jhipster 模块来更改 jhipster 应用程序中的现有源吗?
- c++ - 具有两个链表C ++的对象的复制构造函数
- android - 如何使用 Room Relation 获取另一个 pojo 的列表
- jquery - 如何只让一侧栏作为选项卡式内容 Bootstrap 3.?
- php - 即使使用 DESC LIMIT 并向列添加索引,数据检索也会很慢
- c# - listview的点击事件在xamarin android中不起作用
- swift - 字形图像不会改变颜色
- java - 不支持 JavaFx 系统托盘
- plugins - 安装插件时将数据插入到 drugmart_orderstates 中
- android - Web服务响应Android的通用方法