大家一定在CS/BS的程序有登录窗口,ANDROID也应该是,下面我来做了一个界面欢迎大家参考!

android登录窗口——基础编_休闲

main 代码

 

  1. package net.blogjava.mobile; 
  2.  
  3. import android.app.Activity; 
  4. import android.app.AlertDialog; 
  5. import android.content.DialogInterface; 
  6. import android.os.Bundle; 
  7. import android.view.View; 
  8. import android.view.View.OnClickListener; 
  9. import android.widget.Button; 
  10. import android.widget.LinearLayout; 
  11.  
  12. public class Main extends Activity implements OnClickListener 
  13.     @Override 
  14.     public void onClick(View v) 
  15.     { 
  16.         LinearLayout loginLayout = (LinearLayout) getLayoutInflater().inflate( 
  17.                 R.layout.login, null); 
  18.         new AlertDialog.Builder(this).setIcon(R.drawable.login) 
  19.                 .setTitle("用户登录").setView(loginLayout).setPositiveButton("登录"
  20.                         new DialogInterface.OnClickListener() 
  21.                         { 
  22.                             public void onClick(DialogInterface dialog, 
  23.                                     int whichButton) 
  24.                             { 
  25.                                 // 编写处理用户登录的代码 
  26.                             } 
  27.                         }).setNegativeButton("取消"
  28.                         new DialogInterface.OnClickListener() 
  29.                         { 
  30.                             public void onClick(DialogInterface dialog, 
  31.                                     int whichButton) 
  32.                             { 
  33.                                 // 取消用户登录,退出程序 
  34.  
  35.                             } 
  36.                         }).show(); 
  37.  
  38.     } 
  39.  
  40.     @Override 
  41.     public void onCreate(Bundle savedInstanceState) 
  42.     { 
  43.         super.onCreate(savedInstanceState); 
  44.         setContentView(R.layout.main); 
  45.         Button button = (Button) findViewById(R.id.button); 
  46.         button.setOnClickListener(this); 
  47.  
  48.     }