源代码:
AlertDialog dialog;
AlertDialog.Builder alterDialog = new AlertDialog.Builder(getActivity(), R.style.MyDialog);
alterDialog.setView(R.layout.land_set_passward_dialog);//加载进去
dialog = alterDialog.create();
//显示
dialog.show();
//自定义的东西
//放在show()之后,不然有些属性是没有效果的,比如height和width
Window dialogWindow = dialog.getWindow();
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数
p.gravity = Gravity.CENTER;//设置位置
p.height = (int) (d.getHeight() * 0.83); // 高度设置为屏幕的0.85
p.width = (int) (d.getWidth() * 0.67); // 宽度设置为屏幕的0.75
dialogWindow.setAttributes(p);
TextView dialogTitle = dialog.findViewById(R.id.tvTitle);
dialogTitle.setText(s);
editPwd = dialog.findViewById(R.id.editLoginPwd);
surePwd = dialog.findViewById(R.id.sureChangePwd);
Button btnSure = dialog.findViewById(R.id.btPwdConfirm);
btnSure.setOnClickListener(this);
xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/bankScroll"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:scrollbars="none">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/bankConstraint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/dialog_samail_bg">
<TextView
android:id="@+id/textOne"
android:layout_width="@dimen/size_80"
android:layout_height="wrap_content"
android:gravity="right"
android:text="卡号"
android:textColor="@color/color_AC4745"
android:textSize="@dimen/size_16"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="@dimen/size_80"
android:layout_marginTop="@dimen/size_104"/>
<EditText
android:id="@+id/bankNum"
android:layout_width="0dp"
android:layout_height="@dimen/size_34"
an