如果我使用 Modal BottomSheetFragment 如何添加 BottomSheetBehavior ?
var bottomSheetBehaviorCallback =
object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, slideOffset: Float) {
Log.d(Constants.LOG_INFO, "on slide")
}
override fun onStateChanged(bottomSheet: View, newState: Int) {
Log.d(Constants.LOG_INFO, "onStateChanged")
}
}
val detailView = StationDetailFragment.newInstance(selectedStationID, "")
detailView.show(fragmentManager, "detailView")
Run Code Online (Sandbox Code Playgroud)
此时视图尚未创建
我更改了代码并添加了覆盖 setupDialog 。但我仍然没有得到回调工作
override fun setupDialog(dialog: Dialog?, style: Int) {
val contentView = View.inflate(context, R.layout.fragment_station_detail, null)
dialog!!.setContentView(contentView)
val layoutParams = (contentView.parent as View).layoutParams as CoordinatorLayout.LayoutParams
val behavior = layoutParams.behavior
if (behavior != null && behavior is BottomSheetBehavior<*>) …Run Code Online (Sandbox Code Playgroud)