[英]Android, Modal Bottom sheet dialog, height
我想用关闭按钮创建模态底部工作表对话框并给他自定义高度,我尝试使用dismiss()
,但它不起作用。
给出这个错误:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at com.example.weget.ui.home.HomeFragment .onViewCreated(HomeFragment.kt:41)
我的代码:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
todayPromosList.adapter = homeFragmentAdapter
todayPromosList.layoutManager =
LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
toursList.adapter = homeFragmentAdapter
toursList.layoutManager =
LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
promotionList.adapter = homeFragmentAdapter
promotionList.layoutManager =
GridLayoutManager(context, 2)
val bottomSheetDialog = BottomSheetDialog(context!!)
bottomSheetDialog.setContentView(R.layout.dialog_search)
bottomSheetDialog.setCancelable(false)
home_search.setOnClickListener {
bottomSheetDialog.show()
}
search_dialog_ic_close.setOnClickListener {
bottomSheetDialog.dismiss()
}
}
}
You can set a bottomSheetDialogTheme in your Activity,
overriding the bottomSheetStyle attribute's behavior_peekHeight:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
<style name="AppBottomSheetDialogTheme"
parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>
<style name="AppModalStyle"
parent="Widget.Design.BottomSheet.Modal">
<item name="behavior_peekHeight">@dimen/custom_peek_height</item>
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.