Android 登录对话框 实现

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout 
  3.   xmlns:android="http://schemas.android.com/apk/res/android" 
  4.   android:orientation="vertical" 
  5.   android:layout_width="fill_parent" 
  6.   android:layout_height="fill_parent"> 
  7. <TextView  
  8.     android:id="@+id/AccountTextView" 
  9.     android:layout_width="wrap_content" 
  10.     android:layout_height="wrap_content" 
  11.     android:layout_marginLeft="20dip" 
  12.     android:text="账号" 
  13.     android:gravity="left" 
  14. /> 
  15. <EditText  
  16.     android:id="@+id/AccountEditText" 
  17.     android:layout_width="fill_parent" 
  18.     android:layout_height="fill_parent" 
  19.     android:layout_marginLeft="20dip" 
  20.     android:layout_marginRight="20dip" 
  21.     android:scrollHorizontally="true" 
  22.     android:autoText="false" 
  23.     android:capitalize="none" 
  24.     android:gravity="fill_horizontal" 
  25. /> 
  26. <TextView  
  27.     android:id="@+id/PasswordTextView" 
  28.     android:layout_width="wrap_content" 
  29.     android:layout_height="wrap_content" 
  30.     android:layout_marginLeft="20dip" 
  31.     android:text="密码" 
  32.     android:gravity="left" 
  33. /> 
  34. <EditText  
  35.     android:id="@+id/PasswordEidtText" 
  36.     android:layout_width="fill_parent" 
  37.     android:layout_height="fill_parent" 
  38.     android:layout_marginLeft="20dip" 
  39.     android:layout_marginRight="20dip" 
  40.     android:scrollHorizontally="true" 
  41.     android:autoText="false" 
  42.     android:capitalize="none" 
  43.     android:gravity="fill_horizontal" 
  44.     android:password="true" 
  45. /> 
  46. </LinearLayout> 
[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   android:orientation="vertical"  
  5.   android:layout_width="fill_parent"  
  6.   android:layout_height="fill_parent">  
  7. <TextView   
  8.     android:id="@+id/AccountTextView"  
  9.     android:layout_width="wrap_content"  
  10.     android:layout_height="wrap_content"  
  11.     android:layout_marginLeft="20dip"  
  12.     android:text="账号"  
  13.     android:gravity="left"  
  14. />  
  15. <EditText   
  16.     android:id="@+id/AccountEditText"  
  17.     android:layout_width="fill_parent"  
  18.     android:layout_height="fill_parent"  
  19.     android:layout_marginLeft="20dip"  
  20.     android:layout_marginRight="20dip"  
  21.     android:scrollHorizontally="true"  
  22.     android:autoText="false"  
  23.     android:capitalize="none"  
  24.     android:gravity="fill_horizontal"  
  25. />  
  26. <TextView   
  27.     android:id="@+id/PasswordTextView"  
  28.     android:layout_width="wrap_content"  
  29.     android:layout_height="wrap_content"  
  30.     android:layout_marginLeft="20dip"  
  31.     android:text="密码"  
  32.     android:gravity="left"  
  33. />  
  34. <EditText   
  35.     android:id="@+id/PasswordEidtText"  
  36.     android:layout_width="fill_parent"  
  37.     android:layout_height="fill_parent"  
  38.     android:layout_marginLeft="20dip"  
  39.     android:layout_marginRight="20dip"  
  40.     android:scrollHorizontally="true"  
  41.     android:autoText="false"  
  42.     android:capitalize="none"  
  43.     android:gravity="fill_horizontal"  
  44.     android:password="true"  
  45. />  
  46. </LinearLayout>  


Activity

[java]  view plain copy
  1. package com.zeph.android; 
  2.  
  3. import android.app.Activity; 
  4. import android.app.AlertDialog; 
  5. import android.app.ProgressDialog; 
  6. import android.content.DialogInterface; 
  7. import android.os.Bundle; 
  8. import android.view.LayoutInflater; 
  9. import android.view.View; 
  10.  
  11. public class Android_DialogActivity extends Activity { 
  12.     /** Called when the activity is first created. */ 
  13.     ProgressDialog p_dialog; 
  14.  
  15.     @Override 
  16.     public void onCreate(Bundle savedInstanceState) { 
  17.         super.onCreate(savedInstanceState); 
  18.         setContentView(R.layout.main); 
  19.         AlertDialog dialog = new AlertDialog.Builder( 
  20.                 Android_DialogActivity.this
  21.                 .setTitle("登录提示"
  22.                 .setMessage("是否登录"
  23.                 .setPositiveButton("确定"new DialogInterface.OnClickListener() { 
  24.  
  25.                     @Override 
  26.                     public void onClick(DialogInterface dialog, int which) { 
  27.                         // TODO Auto-generated method stub 
  28.                         LayoutInflater factory = LayoutInflater 
  29.                                 .from(Android_DialogActivity.this); 
  30.                         final View DialogView = factory.inflate( 
  31.                                 R.layout.dialog, null); 
  32.                         AlertDialog dlg = new AlertDialog.Builder( 
  33.                                 Android_DialogActivity.this
  34.                                 .setTitle("登陆框"
  35.                                 .setView(DialogView) 
  36.                                 .setPositiveButton("确定"
  37.                                         new DialogInterface.OnClickListener() { 
  38.  
  39.                                             @Override 
  40.                                             public void onClick( 
  41.                                                     DialogInterface dialog, 
  42.                                                     int which) { 
  43.                                                 // TODO Auto-generated method 
  44.                                                 // stub 
  45.                                                 p_dialog = ProgressDialog 
  46.                                                         .show(Android_DialogActivity.this
  47.                                                                 "请等待"
  48.                                                                 "正在为您登录..."
  49.                                                                 true); 
  50.                                                 new Thread() { 
  51.                                                     public void run() { 
  52.                                                         try { 
  53.                                                             sleep(3000); 
  54.                                                         } catch (Exception e) { 
  55.                                                             e.printStackTrace(); 
  56.                                                         } finally { 
  57.                                                             p_dialog.dismiss(); 
  58.                                                         } 
  59.                                                     } 
  60.                                                 }.start(); 
  61.                                             } 
  62.                                         }) 
  63.                                 .setNegativeButton("取消"
  64.                                         new DialogInterface.OnClickListener() { 
  65.  
  66.                                             @Override 
  67.                                             public void onClick( 
  68.                                                     DialogInterface dialog, 
  69.                                                     int which) { 
  70.                                                 // TODO Auto-generated method 
  71.                                                 // stub 
  72.                                                 Android_DialogActivity.this 
  73.                                                         .finish(); 
  74.                                             } 
  75.                                         }).create(); 
  76.                         dlg.show(); 
  77.  
  78.                     } 
  79.                 }) 
  80.                 .setNegativeButton("退出"new DialogInterface.OnClickListener() { 
  81.  
  82.                     @Override 
  83.                     public void onClick(DialogInterface dialog, int which) { 
  84.                         // TODO Auto-generated method stub 
  85.                         Android_DialogActivity.this.finish(); 
  86.                     } 
  87.                 }).create(); 
  88.         dialog.show(); 
  89.     } 
[java]  view plain  copy
  1. package com.zeph.android;  
  2.   
  3. import android.app.Activity;  
  4. import android.app.AlertDialog;  
  5. import android.app.ProgressDialog;  
  6. import android.content.DialogInterface;  
  7. import android.os.Bundle;  
  8. import android.view.LayoutInflater;  
  9. import android.view.View;  
  10.   
  11. public class Android_DialogActivity extends Activity {  
  12.     /** Called when the activity is first created. */  
  13.     ProgressDialog p_dialog;  
  14.   
  15.     @Override  
  16.     public void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.main);  
  19.         AlertDialog dialog = new AlertDialog.Builder(  
  20.                 Android_DialogActivity.this)  
  21.                 .setTitle("登录提示")  
  22.                 .setMessage("是否登录")  
  23.                 .setPositiveButton("确定"new DialogInterface.OnClickListener() {  
  24.   
  25.                     @Override  
  26.                     public void onClick(DialogInterface dialog, int which) {  
  27.                         // TODO Auto-generated method stub  
  28.                         LayoutInflater factory = LayoutInflater  
  29.                                 .from(Android_DialogActivity.this);  
  30.                         final View DialogView = factory.inflate(  
  31.                                 R.layout.dialog, null);  
  32.                         AlertDialog dlg = new AlertDialog.Builder(  
  33.                                 Android_DialogActivity.this)  
  34.                                 .setTitle("登陆框")  
  35.                                 .setView(DialogView)  
  36.                                 .setPositiveButton("确定",  
  37.                                         new DialogInterface.OnClickListener() {  
  38.   
  39.                                             @Override  
  40.                                             public void onClick(  
  41.                                                     DialogInterface dialog,  
  42.                                                     int which) {  
  43.                                                 // TODO Auto-generated method  
  44.                                                 // stub  
  45.                                                 p_dialog = ProgressDialog  
  46.                                                         .show(Android_DialogActivity.this,  
  47.                                                                 "请等待",  
  48.                                                                 "正在为您登录...",  
  49.                                                                 true);  
  50.                                                 new Thread() {  
  51.                                                     public void run() {  
  52.                                                         try {  
  53.                                                             sleep(3000);  
  54.                                                         } catch (Exception e) {  
  55.                                                             e.printStackTrace();  
  56.                                                         } finally {  
  57.                                                             p_dialog.dismiss();  
  58.                                                         }  
  59.                                                     }  
  60.                                                 }.start();  
  61.                                             }  
  62.                                         })  
  63.                                 .setNegativeButton("取消",  
  64.                                         new DialogInterface.OnClickListener() {  
  65.   
  66.                                             @Override  
  67.                                             public void onClick(  
  68.                                                     DialogInterface dialog,  
  69.                                                     int which) {  
  70.                                                 // TODO Auto-generated method  
  71.                                                 // stub  
  72.                                                 Android_DialogActivity.this  
  73.                                                         .finish();  
  74.                                             }  
  75.                                         }).create();  
  76.                         dlg.show();  
  77.   
  78.                     }  
  79.                 })  
  80.                 .setNegativeButton("退出"new DialogInterface.OnClickListener() {  
  81.   
  82.                     @Override  
  83.                     public void onClick(DialogInterface dialog, int which) {  
  84.                         // TODO Auto-generated method stub  
  85.                         Android_DialogActivity.this.finish();  
  86.                     }  
  87.                 }).create();  
  88.         dialog.show();  
  89.     }  
  90. }  


Android 登录对话框 实现_第1张图片

Android 登录对话框 实现_第2张图片

Android 登录对话框 实现_第3张图片

Android 登录对话框 实现_第4张图片

你可能感兴趣的:(Android 登录对话框 实现)