Warning box of Android Studio notes-realization of pop-up window

#Project structure
Insert picture description here
Click the button to pop up the code

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv_quickReg = findViewById(R.id.tv_quickReg);
        tv_quickReg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TableLayout loginForm = (TableLayout) getLayoutInflater()
                        .inflate(R.layout.login, null);
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setIcon(R.drawable.hat)
                        .setTitle("快速注册")
                        .setView(loginForm)
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", null)
                        .create().show();
            }
        });
//btn_exit是退出按钮的id
        Button btn_exit = findViewById(R.id.btn_exit);
        btn_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setIcon(R.drawable.alert)
                        .setTitle("退出?")
                        .setMessage("确定要退出吗?")
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        })
                        .create().show();
            }
        });
  
    

<TableRow>

    <TextView
        android:id="@+id/text_user"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/username"
        android:textSize="9pt" />

    <EditText
        android:id="@+id/edit_user"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:background="@drawable/editext_selector"
        android:hint="@string/hint_user"
        android:inputType="textPersonName" />
</TableRow>

<TableRow>

    <TextView
        android:id="@+id/text_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/password"
        android:textSize="9pt" />

    <EditText
        android:id="@+id/editpassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:background="@drawable/editext_selector"
        android:hint="@string/hint_password"
        android:inputType="textPassword"
        android:selectAllOnFocus="true" />
</TableRow>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"></LinearLayout>

<TextView
    android:id="@+id/text_show"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Guess you like

Origin blog.csdn.net/qq_43398404/article/details/109290958