我想使用关闭按钮创建模式底部工作表对话框,并给他自定义高度,我尝试使用dismiss()
,但它不起作用。
给出此错误:
原因:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“ void android.widget.ImageButton.setOnClickListener(android.view.View $ OnClickListener)” 在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()
}
}
}
答案 0 :(得分:0)
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>