效果图

自定义activity_userinfo.xml文件代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:padding="10dp" android:layout_height="100dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginTop="20dp" android:orientation="horizontal" tools:ignore="MissingConstraints"> <TextView android:layout_width="58dp" android:layout_height="20dp" android:layout_marginStart="5dp" android:background="#ffffffff" android:text="工 单 号" android:textSize="14sp" android:textStyle="bold" android:textAlignment="textEnd" tools:ignore="HardcodedText" /> <EditText android:id="@+id/txtWorkId" android:layout_width="match_parent" android:layout_height="40dp" android:autofillHints="10dp" android:inputType="text|textNoSuggestions" android:maxLines = "1" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginTop="5dp" android:orientation="horizontal" tools:ignore="MissingConstraints"> <TextView android:layout_width="58dp" android:layout_height="20dp" android:layout_marginStart="5dp" android:background="#ffffffff" android:text="用 户 号" android:textSize="14sp" android:textStyle="bold" android:textAlignment="textEnd" tools:ignore="HardcodedText" /> <EditText android:id="@+id/txtUserId" android:layout_width="match_parent" android:layout_height="40dp" android:autofillHints="14dp" android:inputType="text|textNoSuggestions" android:maxLines = "1" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginTop="5dp" android:orientation="horizontal" tools:ignore="MissingConstraints"> <TextView android:layout_width="58dp" android:layout_height="20dp" android:layout_marginStart="5dp" android:background="#ffffffff" android:text="用 户 名" android:textSize="14sp" android:textStyle="bold" android:textAlignment="textEnd" tools:ignore="HardcodedText" /> <EditText android:id="@+id/txtUserName" android:layout_width="match_parent" android:layout_height="40dp" android:autofillHints="14dp" android:inputType="text|textNoSuggestions" android:maxLines = "1" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginTop="5dp" android:orientation="horizontal" tools:ignore="MissingConstraints"> <TextView android:layout_width="58dp" android:layout_height="20dp" android:layout_marginStart="5dp" android:background="#ffffffff" android:text="用户地址" android:textSize="14sp" android:textAlignment="textEnd" android:textStyle="bold" tools:ignore="HardcodedText" /> <EditText android:id="@+id/txtUserAddress" android:layout_width="match_parent" android:layout_height="40dp" android:autofillHints="14dp" android:inputType="text|textNoSuggestions" android:maxLines = "1" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginTop="5dp" android:orientation="horizontal" tools:ignore="MissingConstraints"> <TextView android:layout_width="58dp" android:layout_height="20dp" android:layout_marginStart="5dp" android:background="#ffffffff" android:text="主 表 号" android:textSize="14sp" android:textStyle="bold" android:textAlignment="textEnd" tools:ignore="HardcodedText" /> <EditText android:id="@+id/txtBH" android:layout_width="match_parent" android:layout_height="40dp" android:autofillHints="14dp" android:inputType="text|textNoSuggestions" android:maxLines = "1" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginTop="5dp" android:orientation="horizontal" tools:ignore="MissingConstraints"> <TextView android:layout_width="58dp" android:layout_height="20dp" android:layout_marginStart="5dp" android:background="#ffffffff" android:text="校 验 员" android:textSize="14sp" android:textStyle="bold" android:textAlignment="textEnd" tools:ignore="HardcodedText" /> <EditText android:id="@+id/txtJYY" android:layout_width="match_parent" android:layout_height="40dp" android:autofillHints="14dp" android:inputType="text|textNoSuggestions" android:maxLines = "1" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" android:gravity="center" tools:ignore="MissingConstraints"> <Button android:id="@+id/btnOK" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:text="保存" tools:ignore="HardcodedText,MissingConstraints" tools:layout_editor_absoluteX="53dp" tools:layout_editor_absoluteY="57dp" /> <Button android:id="@+id/btnCancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="20dp" android:text="取消" tools:ignore="HardcodedText,MissingConstraints" tools:layout_editor_absoluteX="53dp" tools:layout_editor_absoluteY="57dp" /> </LinearLayout> </LinearLayout>
弹出对话框Kotlit代码
fun customDialog(context:Context?){
val builder = AlertDialog.Builder(context)
val inflater: LayoutInflater = LayoutInflater.from(context)
val dialogView = inflater.inflate(R.layout.activity_userinfo, null)
builder.setView(dialogView)
val btnOk = dialogView.findViewById<Button>(R.id.btnOK)
val btnCancel = dialogView.findViewById<Button>(R.id.btnCancel)
val txtWorkId = dialogView.findViewById<EditText>(R.id.txtWorkId)
val txtUserId = dialogView.findViewById<EditText>(R.id.txtUserId)
val txtUserName = dialogView.findViewById<EditText>(R.id.txtUserName)
val txtUserAddress = dialogView.findViewById<EditText>(R.id.txtUserAddress)
val txtBH = dialogView.findViewById<EditText>(R.id.txtBH)
val txtJYY = dialogView.findViewById<EditText>(R.id.txtJYY)
//设置控件初始化值
// txtWorkId.setText(configDal?.getValue("txtWorkId"))
// txtUserId.setText(configDal?.getValue("txtUserId"))
// txtUserName.setText(configDal?.getValue("txtUserName"))
// txtUserAddress.setText(configDal?.getValue("txtUserAddress"))
// txtBH.setText(configDal?.getValue("txtBH"))
// txtJYY.setText(configDal?.getValue("txtJYY"))
val alertDialog = builder.create()
btnOk.setOnClickListener {
alertDialog.dismiss()
//保存最近设置控件初始化值
//configDal?.saveOrUpdateData("txtWorkId", txtWorkId.text.toString())
//configDal?.saveOrUpdateData("txtUserId", txtUserId.text.toString())
//configDal?.saveOrUpdateData("txtUserName", txtUserName.text.toString())
//configDal?.saveOrUpdateData("txtUserAddress", txtUserAddress.text.toStr
//configDal?.saveOrUpdateData("txtBH", txtBH.text.toString())
//configDal?.saveOrUpdateData("txtJYY", txtJYY.text.toString())
//jyData.WorkId = txtWorkId.text.toString()
//jyData.UserId = txtUserId.text.toString()
//jyData.UserName = txtUserName.text.toString()
//jyData.UserAddress = txtUserAddress.text.toString()
//jyData.BH = txtBH.text.toString()
//jyData.JYY = txtJYY.text.toString()
//val dal= JYMainDal(this.context)
////写入数据库
//dal.add(jyData)
}
btnCancel.setOnClickListener {
alertDialog.dismiss()
}
alertDialog.setCancelable(false)//点击空白处不关闭
alertDialog.show()
}本文来自 www.LuoFenMing.com