爱玺玺

爱玺玺的生活日记本。wx:lb87626

androd AlertDialog的使用,弹窗对话框

protected void showSetPassWrodDialog() {

AlertDialog.Builder builder=new Builder(this);

//设置对话框不能消失,返回键也将不能用

builder.setCancelable(false);

View view = View.inflate(getApplicationContext(), R.layout.dialog_setpassword, null);

EditText dialog_setpassword=(EditText) view.findViewById(R.id.dialog_setpassword);

EditText dialog_setpassword2=(EditText) view.findViewById(R.id.dialog_setpassword2);

Button dialong_setpassword_confirm=(Button) view.findViewById(R.id.dialong_setpassword_confirm);

Button dialog_setpassword_cancel=(Button) view.findViewById(R.id.dialog_setpassword_cancel);

dialog_setpassword_cancel.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// 隐藏对话框

dialog.dismiss();

}

});

builder.setView(view);

//先创建一个dialog对象,必须在setView后面创建,不然没有样式显示

dialog = builder.create();

dialog.show();

}


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >


    <TextView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:background="#8866ff00"

        android:gravity="center"

        android:paddingBottom="5dp"

        android:paddingTop="5dp"

        android:textColor="#000000"

        android:text="设置密码"

        android:textSize="22sp" />


    <EditText

        android:id="@+id/dialog_setpassword"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:ems="10"

        android:hint="输入密码"

        android:inputType="textPassword"

        android:textColor="#000000" />



    <EditText

        android:id="@+id/dialog_setpassword2"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:ems="10"

        android:hint="确认密码"

        android:inputType="textPassword"

        android:textColor="#000000" />


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal" >


        <Button

            android:id="@+id/dialong_setpassword_confirm"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="确认"

            android:layout_weight="1"

            android:textColor="#000000" />


        <Button

            android:id="@+id/dialog_setpassword_cancel"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="取消"

            android:layout_weight="1"

            android:textColor="#000000" />

    </LinearLayout>


</LinearLayout>


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5