dialog.xml用于设置DialogView
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/AccountTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:text="账号" android:gravity="left" /> <EditText android:id="@+id/AccountEditText" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:scrollHorizontally="true" android:autoText="false" android:capitalize="none" android:gravity="fill_horizontal" /> <TextView android:id="@+id/PasswordTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:text="密码" android:gravity="left" /> <EditText android:id="@+id/PasswordEidtText" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:scrollHorizontally="true" android:autoText="false" android:capitalize="none" android:gravity="fill_horizontal" android:password="true" /> </LinearLayout>
Activity
package com.zeph.android; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; public class Android_DialogActivity extends Activity { /** Called when the activity is first created. */ ProgressDialog p_dialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog dialog = new AlertDialog.Builder( Android_DialogActivity.this) .setTitle("登录提示") .setMessage("是否登录") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub LayoutInflater factory = LayoutInflater .from(Android_DialogActivity.this); final View DialogView = factory.inflate( R.layout.dialog, null); AlertDialog dlg = new AlertDialog.Builder( Android_DialogActivity.this) .setTitle("登陆框") .setView(DialogView) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int which) { // TODO Auto-generated method // stub p_dialog = ProgressDialog .show(Android_DialogActivity.this, "请等待", "正在为您登录...", true); new Thread() { public void run() { try { sleep(3000); } catch (Exception e) { e.printStackTrace(); } finally { p_dialog.dismiss(); } } }.start(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int which) { // TODO Auto-generated method // stub Android_DialogActivity.this .finish(); } }).create(); dlg.show(); } }) .setNegativeButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Android_DialogActivity.this.finish(); } }).create(); dialog.show(); } }



