今天介绍一种Android登录对话框的实现。
dialog.xml用于设置DialogView

Activity

packagecom.study.android;

importandroid.app.Activity;

importandroid.app.AlertDialog;

importandroid.app.ProgressDialog;

importandroid.content.DialogInterface;

importandroid.os.Bundle;

importandroid.view.LayoutInflater;

importandroid.view.View;

publicclass Android_DialogActivity extends Activity {

/** Called when the activity is firstcreated. */

ProgressDialog p_dialog;

@Override

public void onCreate(BundlesavedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

AlertDialog dialog = newAlertDialog.Builder(

Android_DialogActivity.this)

.setTitle("登录提示")

.setMessage("是否登录")

.setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override

public voidonClick(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 = newAlertDialog.Builder(

Android_DialogActivity.this)

.setTitle("登陆框")

.setView(DialogView)

.setPositiveButton("确定",

newDialogInterface.OnClickListener() {

@Override

public void onClick(

DialogInterface dialog,

int which) {

// TODO Auto-generated method

// stub

p_dialog = ProgressDialog

.show(Android_DialogActivity.this,

"请等待",

"正在为您登录...",

true);

newThread() {

publicvoid run() {

try{

sleep(3000);

}catch (Exception e) {

}finally {

p_dialog.dismiss();

}

}

}.start();

}

})

.setNegativeButton("取消",

newDialogInterface.OnClickListener() {

@Override

public void onClick(

DialogInterface dialog,

int which) {

// TODOAuto-generated method

// stub

Android_DialogActivity.this

.finish();

}

}).create();

dlg.show();

}

})

.setNegativeButton("退出", new DialogInterface.OnClickListener() {

@Override

publicvoid onClick(DialogInterface dialog, int which) {

//TODO Auto-generated method stub

Android_DialogActivity.this.finish();

}

}).create();

dialog.show();

}

}

部分代码取自IT在线教育平台麦子学院,在此注明。

更多相关文章

  1. 使Activity以对话框的形式弹出来
  2. Android日期对话框
  3. android 自定义基于组件的注册用户对话框
  4. android对话框(非速成)
  5. Android:增强目录选择器对话框
  6. Android Dialog 对话框例子

随机推荐

  1. Android创建sdcard
  2. Android(安卓)Jetpack系列之Lifecycle组
  3. android开发中如何获得应用的数字签名
  4. Android常用adb命令总结(一)
  5. Android产品开发经验谈
  6. 编译android 之后生成的 img 文件介绍
  7. android中activity的四种加载模式
  8. 做android遇到有问题有感
  9. android - 模拟器连接本地tomcat
  10. Android(安卓)webview 应用