dip*_*dip 17 android android-softkeyboard android-toolbar bottom-sheet
如何BottomSheetDialog(Fragment)使用ToolBar 创建一个切换到全屏的模态,如材料设计规范中所示?
我可以通过添加a BottomSheetBehavior.BottomSheetCallback并根据slideOffset设置ToolBar的alpha来手动添加ToolBar.移动底板时,这有点像hacky但似乎有效.但是,当我的底部工作表包含EditText并显示键盘时,这不起作用.我尝试了两个版本:BottomSheetDialogFragment并手动将行为添加到新片段.
Tin*_* Lu -2
我面临同样的问题。这就是我解决的。行为隐藏在BottomSheetDialog中,可以通过BottomSheetDialog获取行为如果您不想将父布局更改为CooridateLayout,您可以尝试这样做。
第 1 步:自定义 BottomSheetDialogFragment
open class CBottomSheetDialogFragment : BottomSheetDialogFragment() {
//wanna get the bottomSheetDialog
protected lateinit var dialog : BottomSheetDialog
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
return dialog
}
//set the behavior here
fun setFullScreen(){
dialog.behavior.state = STATE_EXPANDED
}
}
Run Code Online (Sandbox Code Playgroud)
第 2 步:使您的片段扩展此自定义片段
class YourBottomSheetFragment : CBottomSheetDialogFragment(){
//make sure invoke this method after view is built
//such as after OnActivityCreated(savedInstanceState: Bundle?)
override fun onStart() {
super.onStart()
setFullScreen()//initiated at onActivityCreated(), onStart()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1164 次 |
| 最近记录: |