android 自定义弹出窗口

首先自定义一个布局文件

android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="50dip"
android:gravity="center"
android:orientation="vertical">
android:id="@+id/txt_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center"
android:textColor="@color/black"
android:textSize="30dp" />

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical">
android:id="@+id/txt_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:textColor="@color/black"
android:textSize="22dp" />

android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:gravity="center">
android:id="@+id/btn_cancel"
android:layout_width="120dip"
android:layout_height="40dip"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginRight="20dp"
android:background="@drawable/button_setting_style"
android:text="取消"
android:textSize="24dp" />
android:id="@+id/btn_exit"
android:layout_width="120dip"
android:layout_height="40dip"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginLeft="20dp"
android:text="注销"
android:textSize="24dp"
android:background="@drawable/button_setting_style"
/>

private void initDialog() {
    exitDialog = new AlertDialog.Builder(activity).create();
    viewDialog = activity.getLayoutInflater().inflate(R.layout.layout_exit_dialog, null);
    viewDialog.setMinimumHeight((int) (CommonUtil.getScreen(activity).heightPixels * 0.3));
    viewDialog.setMinimumWidth((int) (CommonUtil.getScreen(activity).widthPixels * 0.4));
    txt_title = (TextView)viewDialog.findViewById(R.id.txt_title);
    txt_content = (TextView) viewDialog.findViewById(R.id.txt_content);
    btn_exit = (Button)viewDialog.findViewById(R.id.btn_exit);
    btn_cancel = (Button) viewDialog.findViewById(R.id.btn_cancel);
    btn_exit.setOnClickListener(this);
    btn_cancel.setOnClickListener(this);
    exitDialog.setView(viewDialog, 0, 0, 0, 0);
    exitDialog.setCanceledOnTouchOutside(true);
    exitDialog.setCancelable(true);
}

private void showDialog(){
    txt_title.setText("标题");
    txt_content.setText("内容");
    exitDialog.show();
}

 

 

 

 

你可能感兴趣的:(Android内容,android,dialog)