BottomSheetDialog底部按钮
BottomSheetDialog底部按钮
七水剑帝 发表于11个月前
BottomSheetDialog底部按钮
  • 发表于 11个月前
  • 阅读 1
  • 收藏 0
  • 点赞 0
  • 评论 0

移动开发云端新模式探索实践 >>>   

http://www.jianshu.com/u/35167a70aa39

private void showShareDialog(){
    if(mBottomSheetDialog == null){
        mBottomSheetDialog = new MyBottomSheetDialog(getActivity());
        View v=LayoutInflater.from(getActivity()).inflate(R.layout.bottom_sheet_share_dialog,null);
        mBottomSheetDialog.setContentView(v);
        mBottomSheetDialog.setCancelable(true);
        mBottomSheetDialog.setCanceledOnTouchOutside(true);
        //点击事件
        SuperTextView add=V.findViewById(v,R.id.add_menu);
        SuperTextView cancel=V.findViewById(v,R.id.cancel_menu);
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "add", Toast.LENGTH_SHORT).show();
                mBottomSheetDialog.dismiss();
            }
        });
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBottomSheetDialog.dismiss();
            }
        });


        // 解决下滑隐藏dialog 后,再次调用show 方法显示时,不能弹出Dialog
        final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(mBottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet));
        bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                    Log.i("BottomSheet","onStateChanged");
                    mBottomSheetDialog.dismiss();
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {

            }
        });
    }else{
        mBottomSheetDialog.show();
    }

}

 

解决状态栏变色

http://blog.csdn.net/aiynmimi/article/details/66969109

public class MyBottomSheetDialog extends BottomSheetDialog {
    private Context context;
    public MyBottomSheetDialog(@NonNull Context context) {
        super(context);
        this.context=context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int screenHeight = getScreenHeight((Activity) context);
        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;
    }
}

标签: BottomSheetDialog
  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 1
博文 47
码字总数 36879
×
七水剑帝
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: