android dialog 数据传递参数,android自定义Dialog,输入支付密码,带参数回调

自定义工具类

public class PayPurchaDialog extends Dialog implements View.OnClickListener {

private EditText mEtPwd;

private TextView mTvCancel;

private TextView mTvOk;

public PayPurchaDialog(@NonNull Context context) {

this(context, 0);

}

public PayPurchaDialog(@NonNull Context context, int themeResId) {

super(context, themeResId);

View view = View.inflate(context, R.layout.dialog_pay_pwd, null);

mEtPwd = view.findViewById(R.id.dialog_pay_pwd_et_pwd);

view.findViewById(R.id.dialog_pay_pwd_tv_cancel).setOnClickListener(this);

view.findViewById(R.id.dialog_pay_pwd_tv_ok).setOnClickListener(this);

setCancelable(false);

setContentView(view);

changeDialogStyle();

}

/**

* 设置dialog占满屏幕

*/

private void changeDialogStyle() {

Window window = getWindow();

if (window != null) {

WindowManager.LayoutParams attr = window.getAttributes();

if (attr != null) {

attr.height = ViewGroup.LayoutParams.WRAP_CONTENT;

attr.width = ViewGroup.LayoutParams.MATCH_PARENT;

window.setAttributes(attr);

}

}

}

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.dialog_pay_pwd_tv_cancel:

dismiss();

break;

case R.id.dialog_pay_pwd_tv_ok:

String payPwd = mEtPwd.getText().toString();

if (!TextUtils.isEmpty(payPwd)) {

if (mOnOkClick != null) {

mOnOkClick.onOkClick(payPwd);

}

}

dismiss();

break;

}

}

public void setOnOkClick(OnOkClick onOkClick){

mOnOkClick = onOkClick;

}

private OnOkClick mOnOkClick;

public interface OnOkClick{

void onOkClick(String payPwd);

}

dialog_pay_pwd.xml文件

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#0000">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/dialog_activate_shape"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:padding="6dp"

android:textSize="22sp"

android:text="交易密码"

android:textColor="#AF00"/>

android:id="@+id/dialog_pay_pwd_et_pwd"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="16dp"

android:layout_marginTop="12dp"

android:layout_marginLeft="30dp"

android:layout_marginRight="30dp"

android:inputType="textPassword"

android:gravity="center"

android:paddingLeft="2dp"

android:paddingRight="2dp"

android:paddingTop="8dp"

android:paddingBottom="8dp"

android:background="@drawable/shape_dialog_pay_pwd_et_bg"

android:hint="请输入交易密码"

android:textColor="#6000"/>

android:layout_width="match_parent"

android:layout_height="1px"

android:background="#C0C0C0"/>

android:layout_width="match_parent"

android:layout_height="50dp"

android:orientation="horizontal">

android:id="@+id/dialog_pay_pwd_tv_cancel"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_gravity="center"

android:layout_weight="1"

android:gravity="center"

android:text="取消" />

android:layout_width="1px"

android:layout_height="wrap_content"

android:background="#C0C0C0"/>

android:id="@+id/dialog_pay_pwd_tv_ok"

android:gravity="center"

android:layout_width="0dp"

android:textColor="#AF00"

android:layout_gravity="center"

android:layout_height="match_parent"

android:layout_weight="1"

android:text="确定"/>

Activity中回调 (写在点击事件中)

PayPurchaDialog dialog = new PayPurchaDialog(mContext);//支付密码弹出框

dialog.setOnOkClick(new PayPurchaDialog.OnOkClick() {

@Override

public void onOkClick(String payPwd) {

//TODO:点击确定, 密码回调在这里 先判断密码,然后调用接口

dialog.dismiss(); //关闭窗口

//带着密码payPwd调用你的方法

}

});

dialog.show();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值