EditText 布局页面 edittext_ownername_dialog.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="车 主 姓 名 输 入" android:layout_marginTop="30dp" android:layout_marginBottom="30dp" android:textSize="18sp" android:textStyle="bold" android:textColor="#fe0000"/> <EditText android:layout_width="300dp" android:layout_height="50dp" android:text="" android:gravity="center" android:hint="请输入车主姓名" android:layout_marginBottom="15dp" android:background="@drawable/bg_edit_text" android:id="@+id/edittext_ownername_dialog" /> </LinearLayout>
java 文件:
@OnClick(R.id.edittext_ownername) public void OnClickOwnerName(View view ){ View v=getLayoutInflater().inflate(R.layout.edittext_ownername_dialog,null); final EditText et=(EditText)v.findViewById(R.id.edittext_ownername_dialog); new AlertDialog.Builder(this).setTitle("") .setIcon(null) .setView(v) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { edittext_ownername.setText(et.getText().toString()); } }).setNegativeButton("取消",null).show(); }