[英]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.