Android AlertDialog,PopupWindow弹窗

AlertDialog:

                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
                        //设置视图,将自定义视图资源设置为 Dialog 的内容.
                        .setView(R.layout.popwindow)
                        //标题
                        .setTitle("弹窗标题")
                        //内容
                        .setMessage("内容")
                        //可取消
                        .setCancelable(false)
                        //按钮是按设置的顺序排列的
                        .setPositiveButton("确定", (dialog, which) -> {
                            returnContent("按钮被点击了");
                        })
                        .setNeutralButton("中间按钮", null)
                        .setNegativeButton("否定按钮", null)
                        .create();
                //显示弹窗
                alertDialog.show();

图片[1]-Android AlertDialog,PopupWindow弹窗-IT网络技术分享

PopupWindow:

                PopupWindow popupWindow = new PopupWindow();
                popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
                popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
                popupWindow.setContentView(View.inflate(MainActivity.this, R.layout.popwindow, null));
                //设置可取消

                //设置背景可绘制
                popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
                //设置可聚焦
                popupWindow.setFocusable(true);
                //设置外部可触摸
                popupWindow.setOutsideTouchable(true);
                //动画样式
                popupWindow.setAnimationStyle(R.style.Animation_AppCompat_Dialog);
                //设置位置
                popupWindow.showAsDropDown(v, 0, 0);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content"
        android:layout_width="100dp"
        android:orientation="vertical"
        android:background="#783131"
        >

    <Button
            android:id="@+id/button"
            android:layout_height="50dp"
            android:layout_width="match_parent"
            android:text="Button"
            />

    <Button
            android:id="@+id/button1"
            android:layout_height="50dp"
            android:layout_width="match_parent"
            android:text="Button"
            />

    <EditText
            android:id="@+id/editTextTextPersonName"
            android:ems="10"
            android:inputType="textPersonName"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="Name"
            />

    <EditText
            android:id="@+id/editTextTime"
            android:ems="10"
            android:inputType="time"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            />

    <EditText
            android:id="@+id/editTextDate"
            android:ems="10"
            android:inputType="date"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            />

    <TextView
            android:id="@+id/textView"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="TextView"
            />

    <EditText
            android:id="@+id/editTextTextEmailAddress"
            android:ems="10"
            android:inputType="textEmailAddress"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            />

</LinearLayout>

图片[2]-Android AlertDialog,PopupWindow弹窗-IT网络技术分享

 

 

THE END
喜欢就支持一下吧
点赞6 分享