首页 > 代码库 > Android实现登录对话框
Android实现登录对话框
今天介绍一种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在线教育平台麦子学院,在此注明。
Android实现登录对话框