Android弹出自定义Dialog,android 自定义Dialog(底部弹窗)

本文介绍了如何在Android中自定义一个可取消的BottomSheet Dialog,并展示了如何通过`ButtomDialogView`类设置其行为和布局。作者详细讲解了如何设置Dialog的可取消性和返回键操作,以及如何根据屏幕尺寸动态调整内部View的布局参数。
摘要由CSDN通过智能技术生成

1、自定义

public class ButtomDialogView extends Dialog {

private boolean iscancelable;//控制点击dialog外部是否dismiss

private boolean isBackCancelable;//控制返回键是否dismiss

private boolean isBackCanCelable;//

private View view;

private Context context;

public ButtomDialogView(Context context, View view, boolean isCancelable,boolean isBackCancelable) {

super(context, R.style.MyDialog);

this.context = context;

this.view = view;

this.iscancelable = isCancelable;

this.isBackCanCelable=isBackCancelable;

}

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

(这里可以R.layout.view)

setContentView(view);//这行一定要写在前面

setCancelable(iscancelable);//点击外部不可dismiss

setCanceledOnTouchOutside(isBackCanCelable);

Window window = this.getWindow();

window.setGravity(Gravity.BOTTOM);

WindowManager.LayoutParams params = window.getAttributes();

params.width = WindowManager.LayoutParams.MATCH_PARENT;//设置宽高模式,

params.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置宽高模式,

window.setAttributes(params);

}

}

2、R.style.MyDialog,在value文件夹下找到style,将下述代码加进去

3、调用

public void showShareTable(){

View contentview = LayoutInflater.from(this).inflate(R.layout.popwindow_detail_share, null);

ButtomDialogView dialogView=new ButtomDialogView(this,contentview,true,true);

dialogView.show();

}

java中调整布局对其等参数;

// # 学校

school_page是Button;

RelativeLayout.LayoutParams schoolParams = (RelativeLayout.LayoutParams) school_page.getLayoutParams();

schoolParams.width = (153 * width / 1334) + 60;

schoolParams.height = 226 * height / 750;

schoolParams.leftMargin = 633 * width / 1334;

schoolParams.topMargin = 227 * height / 750;

school_page.setLayoutParams(schoolParams);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值