Android 原生自定义界面弹框写法

源代码:

   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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值