android edit box pops up

LayoutInflater inflater = LayoutInflater.from(getContext());
               final View viewCategory = inflater.inflate(R.layout.layout_category_add, null);
               final EditText etCategoryName = viewCategory.findViewById(R.id.input_category_name);
               final EditText etSort = viewCategory.findViewById(R.id.input_sort);

                new AlertDialog
                        .Builder(getContext())
                        .setTitle("请输入类目数据")
                        .setView(viewCategory)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                //网络请求

                            }
                        })
                        .setNegativeButton("取消", null)
                        .show();

1, first of all, this pop-up edit box for simple editing actions.
Create edit the layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/layout_category_add">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="3dp">

        <EditText android:id="@+id/input_category_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入商品类目名称"
            android:textSize="12sp"/>
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="3dp">

        <EditText android:id="@+id/input_sort"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:hint="请输入类目排序"
            android:textSize="12sp"/>
    </android.support.design.widget.TextInputLayout>


</LinearLayout>

2, and then set the layout created to AlertDialog

setView()
Published 139 original articles · won praise 35 · views 180 000 +

Guess you like

Origin blog.csdn.net/kanglovejava/article/details/101050643