今天介绍一种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. Android登录页面制作并且记住账号密码
  2. Android(安卓)HTTP GET/POST
  3. android 弹出框
  4. Android监听键盘上的确定键等
  5. android 登录前检查网络状态
  6. Android菜鸟的成长笔记(3)——给QQ登录界面说So Easy
  7. Android逆向分析之dex2jar和jd-gui使用
  8. android中列表选项、单选选项、多选选项对话框的使用
  9. Android(安卓)如何实现带滚动条的TextView,在更新文字时自动滚动

随机推荐

  1. [置顶] android Listview分批加载+自动加
  2. android Messenger
  3. android 位图bitmap
  4. Android(安卓)与 IOS的UUID的区别
  5. Android:嵌入式关系型SQLite数据库、SQLit
  6. android TextView的字体颜色设置的多种方
  7. MAC获取Android(安卓)Studio的发布版SHA1
  8. Gvr SDK for Unity 分析(一)
  9. Android数据存储之SharedPreferences
  10. android usb挂载分析---MountService启动