BottomSheetDialog的使用
2017-02-08 13:56
519 查看
BottomSheetDialog的简单使用
比较坑的地方是:
BottomSheetDialog bsd = new MyBottomSheetDialog(this); bsd.setContentView(R.layout.items);//布局为任意布局 bsd.show();
比较坑的地方是:
1.向下滑动后,再show不出来
当我们设置bottomSheetDialog点击后不new,而是直接show的话,然而当我们会bottomSheetDialog 展开后,我们将BottomSheetDialog划下隐藏后, 再点击展示BottomSheetDialog后,会发现页面只是变暗,BottomsheetDialog未展开,这是由于之前我们划下收缩隐藏BottomSheetDialog后,bottomSheetDialogBehavior的状态为隐藏,再次show之后,系统未恢复bottomSheetDialogBehavior的状态,还是隐藏,所以再次点击后页面只是变暗。(未能解决,暂时只能每次都new)2.解决BottomSheetDialog状态栏变黑的问题
继承BottomSheetDialog并重写其protected void onCreate(Bundle savedInstanceState)方法Activity mActivity; public MyBottomSheetDialog(@NonNull Context context) { super(context); mActivity = (Activity) context; } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int screenHeight = getScreenHeight(mActivity); int statusBarHeight = getStatusBarHeight(getContext()); int dialogHeight = screenHeight - statusBarHeight; getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, dialogHeight == 0 ? ViewGroup.LayoutParams.MATCH_PARENT : dialogHeight); } private static int getScreenHeight(Activity activity) { DisplayMetrics displaymetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); return displaymetrics.heightPixels; } private static int getStatusBarHeight(Context context) { int statusBarHeight = 0; Resources res = context.getResources(); int resourceId = res.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = res.getDimensionPixelSize(resourceId); } return statusBarHeight; }
相关文章推荐
- Bottom Sheet的使用和BottomSheetDialogFragment的封装
- 如何禁止使用bottomsheetdialogfragment拖动?
- BottomSheetDialogFragment 的使用
- BottomSheetDialog的使用
- BottomSheetDialog的使用及注意事项
- 使用 DialogFragment 和 BottomSheet 实现底部弹出框
- Support Design库中的BottomSheetDialog组件使用
- 如何禁止使用bottomsheetdialogfragment拖动?
- 解决使用BottomSheetDialog时状态栏变黑的问题
- Android使用BottomSheetBehavior 和 BottomSheetDialog实现底部弹窗
- 如何使用Material Design中的BottomSheetBehavior、BottomSheetDialog和BottomSheetDialogFragment
- 解决使用BottomSheetDialog时状态栏变黑的问题
- Android 分享界面,使用BottomSheetDialog(可上拉到顶部,可下拉消失,仿知乎、掘金等)
- Android 6.0新控件 BottomSheetDialog | 底部对话框 介绍及使用详情
- 解决使用BottomSheetDialog时状态栏变黑的问题
- 解决使用BottomSheetDialog时状态栏变黑的问题
- Android BottomSheetDialog消失后再次无法显示的处理方法
- 第一篇博客 干掉BottomSheetDialog的默认白色框
- Android Material Design之BottomSheetDialog
- 【Android】BottomSheetDialog详解