当前位置:   article > 正文

Android 一个简单的登录界面(一)

android 登录 test3

本文的demo和素材因为时间太久找不到了

另外一个登陆界面分享见https://my.oschina.net/zengliubao/blog/841279

另外一个登陆界面分享见https://my.oschina.net/zengliubao/blog/841279

164525_Of2d_166646.png

 

 

-----------------------------------------------------------------------------------

 

 

164525_LQpt_166646.png

 

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:custom="http://schemas.android.com/apk/res-auto"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:fitsSystemWindows="true" >
  6.    
  7.     <RelativeLayout
  8.         android:id="@+id/login_layout"
  9.         android:layout_width="fill_parent"
  10.         android:layout_height="wrap_content"
  11.         android:layout_marginLeft="20dp"
  12.         android:layout_marginRight="20dp"
  13.         android:gravity="center" >
  14.         <FrameLayout
  15.             android:id="@+id/username_layout"
  16.             android:layout_width="fill_parent"
  17.             android:layout_height="wrap_content"
  18.             android:layout_marginTop="55dp"
  19.             android:gravity="center" >
  20.             <EditText
  21.                 android:id="@+id/username"
  22.                 android:layout_width="fill_parent"
  23.                 android:layout_height="@dimen/default_edittext_height"
  24.                 android:layout_marginTop="5dp"
  25.                 android:inputType="number"
  26.                 android:paddingRight="60dp"
  27.                 android:maxLength="20"
  28.                 android:paddingLeft="55dp" >
  29.             </EditText>
  30.             <ImageView
  31.                 android:layout_width="22dp"
  32.                 android:layout_height="21dp"
  33.                 android:layout_marginStart="8dp"               
  34.                 android:layout_gravity="left|center_vertical"
  35.                 android:background="@drawable/login_usr_in_img"
  36.                 android:visibility="visible" />
  37.             <TextView
  38.                 android:id="@+id/contry_sn"
  39.                 android:layout_width="40dp"
  40.                 android:layout_height="50dp"
  41.                 android:layout_gravity="left|center_vertical"
  42.                 android:layout_marginTop="4dp"
  43.                 android:gravity="center"
  44.                 android:text="+62"
  45.                 android:textColor="@android:color/black"
  46.                 android:textSize="18sp"
  47.                 android:visibility="invisible" />
  48.             
  49.             <Button 
  50.                 android:id="@+id/bt_username_clear"
  51.                 android:layout_width="23dp"
  52.                 android:layout_height="23dp"
  53.                 android:background="@drawable/button_clear"
  54.                 android:layout_gravity="right|center_vertical"
  55.                 android:layout_marginRight="10dp"
  56.                 android:visibility="invisible"
  57.                 />
  58.         </FrameLayout>
  59.         <FrameLayout
  60.             android:id="@+id/usercode_layout"
  61.             android:layout_width="fill_parent"
  62.             android:layout_height="wrap_content"
  63.             android:layout_below="@id/username_layout"
  64.             android:layout_marginTop="6dp"
  65.             android:gravity="center" >
  66.             <EditText
  67.                 android:id="@+id/password"
  68.                 android:layout_width="fill_parent"
  69.                 android:layout_height="@dimen/default_edittext_height"  //40
  70.                 android:inputType="textPassword"
  71.                 android:paddingRight="60dp"
  72.                 android:maxLength="20"
  73.                 android:paddingLeft="55dp" >
  74.             </EditText>
  75.             <ImageView
  76.                 android:layout_width="24dp"
  77.                 android:layout_height="22dp"
  78.                 android:layout_marginStart="7dp"               
  79.                 android:layout_gravity="left|center_vertical"
  80.                 android:background="@drawable/login_code_in_img" />
  81.                <Button 
  82.                 android:id="@+id/bt_pwd_eye"
  83.                 android:layout_width="23dp"
  84.                 android:layout_height="23dp"
  85.                 android:background="@drawable/button_eye_n"
  86.                 android:layout_gravity="right|center_vertical"
  87.                 android:layout_marginRight="10dp"
  88.                 />
  89.                <Button 
  90.                 android:id="@+id/bt_pwd_clear"
  91.                 android:layout_width="23dp"
  92.                 android:layout_height="23dp"
  93.                 android:background="@drawable/button_clear"
  94.                 android:visibility="invisible"
  95.                 android:layout_gravity="right|center_vertical"
  96.                 android:layout_marginRight="33dp"
  97.                 />
  98.         </FrameLayout>
  99.   
  100.         <Button
  101.             android:id="@+id/login"
  102.             android:layout_width="fill_parent"
  103.             android:layout_height="@dimen/default_button_height"
  104.             android:layout_below="@id/usercode_layout"
  105.             android:layout_marginTop="30dp"
  106.             android:background="#ff336699"
  107.             android:textColor="@android:color/white"
  108.             
  109.             android:gravity="center"
  110.             android:text="登录" />
  111.         <Button
  112.             android:id="@+id/login_error"
  113.             android:layout_width="wrap_content"
  114.             android:layout_height="wrap_content"
  115.             android:layout_alignRight="@id/login"
  116.             android:layout_below="@id/login"
  117.             android:background="#00000000"            
  118.             android:text="忘记密码"
  119.             android:textSize="16sp" />
  120.         <Button
  121.             android:id="@+id/register"
  122.             android:layout_width="wrap_content"
  123.             android:layout_height="wrap_content"
  124.             android:layout_alignLeft="@id/login"
  125.             android:layout_below="@id/login"
  126.             android:background="#00000000"
  127.             android:gravity="left|center_vertical"
  128.             android:text="注册"
  129.             android:textSize="16sp"            
  130.             android:visibility="visible" />
  131.     </RelativeLayout>
  132.     <RelativeLayout
  133.         android:id="@+id/remember_layout000"
  134.         android:layout_width="wrap_content"
  135.         android:layout_height="wrap_content"
  136.         android:layout_alignParentBottom="true"
  137.         android:layout_marginBottom="1dp"
  138.         android:layout_marginLeft="20dp"
  139.         android:layout_marginRight="20dp" >
  140.         <Button
  141.             android:id="@+id/registfer"
  142.             android:layout_width="wrap_content"
  143.             android:layout_height="wrap_content"
  144.             android:background="#00000000"
  145.             android:gravity="center"
  146.             android:singleLine="true"
  147.             android:text="AnyLife,Make the world a better place."
  148.             android:textSize="16sp"
  149.             android:visibility="visible" />
  150.     </RelativeLayout>
  151. </RelativeLayout>
  1. package com.bipbip.activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.os.Handler;
  5. import android.os.Message;
  6. import android.text.Editable;
  7. import android.text.InputType;
  8. import android.text.TextWatcher;
  9. import android.view.KeyEvent;
  10. import android.view.View;
  11. import android.view.View.OnClickListener;
  12. import android.view.View.OnLongClickListener;
  13. import android.widget.Button;
  14. import android.widget.EditText;
  15. import android.widget.RelativeLayout;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18. import com.bipbip.main.BaseActivity;
  19. import com.bipbip.main.MainActivity;
  20. import com.bipbip.watch.R;
  21. /**
  22.  * 
  23.  * 
  24.  *  注      册: ValidatePhoneNumActivity  -->  RegisterActivity
  25.  * 
  26.  *  忘记密码   ForgetCodeActivity        -->  RepasswordActivity
  27.  *   
  28.  *  @author liubao.zeng
  29.  *
  30.  */   
  31. public class LoginActivity extends BaseActivity implements OnClickListener,OnLongClickListener {
  32.  // 声明控件对象
  33.  private EditText et_name, et_pass;
  34.  private Button mLoginButton,mLoginError,mRegister,ONLYTEST;  
  35.  int selectIndex=1;
  36.  int tempSelect=selectIndex;
  37.  boolean isReLogin=false;
  38.  private int SERVER_FLAG=0;
  39.  private RelativeLayout countryselect;
  40.  private TextView   coutry_phone_sn, coutryName;//
  41. // private String [] coutry_phone_sn_array,coutry_name_array;
  42.  public final static int LOGIN_ENABLE=0x01;    //注册完毕了
  43.  public final static int LOGIN_UNABLE=0x02;    //注册完毕了
  44.  public final static int PASS_ERROR=0x03;      //注册完毕了
  45.  public final static int NAME_ERROR=0x04;      //注册完毕了
  46.  final Handler UiMangerHandler = new Handler(){   
  47.   @Override    
  48.   public void handleMessage(Message msg) {  
  49.    // TODO Auto-generated method stub
  50.    switch(msg.what){  
  51.    case LOGIN_ENABLE:  
  52.     mLoginButton.setClickable(true);            
  53. //    mLoginButton.setText(R.string.login);
  54.     break;
  55.    case LOGIN_UNABLE:
  56.     mLoginButton.setClickable(false);
  57.     break;
  58.    case PASS_ERROR:
  59.     
  60.     break;
  61.    case NAME_ERROR:
  62.     break;
  63.    }     
  64.    super.handleMessage(msg);
  65.   }   
  66.  };
  67.  private Button bt_username_clear;
  68.  private Button bt_pwd_clear;
  69.  private Button bt_pwd_eye;
  70.  private TextWatcher username_watcher;       
  71.  private TextWatcher password_watcher;      
  72.  @Override
  73.  protected void onCreate(Bundle savedInstanceState) {
  74.   super.onCreate(savedInstanceState);
  75. //  requestWindowFeature(Window.FEATURE_NO_TITLE);      
  76. //  //不显示系统的标题栏          
  77. //  getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
  78. //    WindowManager.LayoutParams.FLAG_FULLSCREEN );
  79.   
  80.   setContentView(R.layout.activity_login);
  81.   et_name = (EditText) findViewById(R.id.username);
  82.   et_pass = (EditText) findViewById(R.id.password);
  83.   
  84.   bt_username_clear = (Button)findViewById(R.id.bt_username_clear);
  85.   bt_pwd_clear = (Button)findViewById(R.id.bt_pwd_clear);
  86.   bt_pwd_eye = (Button)findViewById(R.id.bt_pwd_eye);
  87.   bt_username_clear.setOnClickListener(this);
  88.   bt_pwd_clear.setOnClickListener(this);
  89.   bt_pwd_eye.setOnClickListener(this);
  90.   initWatcher();
  91.   et_name.addTextChangedListener(username_watcher);
  92.   et_pass.addTextChangedListener(password_watcher);
  93.   
  94.   mLoginButton = (Button) findViewById(R.id.login);
  95.   mLoginError  = (Button) findViewById(R.id.login_error);
  96.   mRegister    = (Button) findViewById(R.id.register);
  97.   ONLYTEST     = (Button) findViewById(R.id.registfer);
  98.   ONLYTEST.setOnClickListener(this);      
  99.   ONLYTEST.setOnLongClickListener((OnLongClickListener) this);
  100.   mLoginButton.setOnClickListener(this);       
  101.   mLoginError.setOnClickListener(this);       
  102.   mRegister.setOnClickListener(this);  
  103.   
  104. //  countryselect=(RelativeLayout) findViewById(R.id.countryselect_layout);
  105. //  countryselect.setOnClickListener(this);
  106. //  coutry_phone_sn=(TextView) findViewById(R.id.contry_sn);
  107. //  coutryName=(TextView) findViewById(R.id.country_name);
  108.  
  109. //  coutryName.setText(coutry_name_array[selectIndex]);    //默认为1
  110. //  coutry_phone_sn.setText("+"+coutry_phone_sn_array[selectIndex]);
  111.  }
  112.  /**
  113.   * 手机号,密码输入控件公用这一个watcher
  114.   */
  115.  private void initWatcher() {
  116.   username_watcher = new TextWatcher() {
  117.    public void onTextChanged(CharSequence s, int start, int before, int count) {}
  118.    public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
  119.    public void afterTextChanged(Editable s) {
  120.     et_pass.setText("");
  121.     if(s.toString().length()>0){
  122.      bt_username_clear.setVisibility(View.VISIBLE);
  123.     }else{
  124.      bt_username_clear.setVisibility(View.INVISIBLE);
  125.     }
  126.    }
  127.   };
  128.   
  129.   password_watcher = new TextWatcher() {
  130.    public void onTextChanged(CharSequence s, int start, int before, int count) {}
  131.    public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
  132.    public void afterTextChanged(Editable s) {
  133.     if(s.toString().length()>0){
  134.      bt_pwd_clear.setVisibility(View.VISIBLE);
  135.     }else{
  136.      bt_pwd_clear.setVisibility(View.INVISIBLE);
  137.     }
  138.    }
  139.   };
  140.  }
  141.   
  142.     
  143.  
  144.  @Override
  145.  public void onClick(View arg0) {
  146.   // TODO Auto-generated method stub
  147.   switch (arg0.getId()) {
  148.   case R.id.login:  //登陆
  149. //   login(); 
  150.    startActivity(MainActivity.class);
  151.    break;
  152.   case R.id.login_error//无法登陆(忘记密码了吧)
  153. //   Intent login_error_intent=new Intent();
  154. //   login_error_intent.setClass(LoginActivity.this, ForgetCodeActivity.class);
  155. //   startActivity(login_error_intent);
  156.    break;
  157.   case R.id.register:    //注册新的用户
  158. //   Intent intent=new Intent();
  159. //   intent.setClass(LoginActivity.this, ValidatePhoneNumActivity.class);
  160. //   startActivity(intent);
  161.    
  162.    break;
  163.   case R.id.registfer:
  164.    if(SERVER_FLAG>10){
  165.     Toast.makeText(this, "[内部测试--谨慎操作]", Toast.LENGTH_SHORT).show();
  166.    }
  167.    SERVER_FLAG++;
  168.    break;
  169.   case R.id.bt_username_clear:
  170.    et_name.setText("");
  171.    et_pass.setText("");
  172.    break;
  173.   case R.id.bt_pwd_clear:
  174.    et_pass.setText("");
  175.    break;
  176.   case R.id.bt_pwd_eye:
  177.    if(et_pass.getInputType() == (InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD)){
  178.     bt_pwd_eye.setBackgroundResource(R.drawable.button_eye_s);
  179.     et_pass.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
  180.    }else{
  181.     bt_pwd_eye.setBackgroundResource(R.drawable.button_eye_n);
  182.     et_pass.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
  183.    }
  184.    et_pass.setSelection(et_pass.getText().toString().length());
  185.    break;
  186.   }
  187.  }
  188.  /**
  189.   * 登陆
  190.   */
  191.  private void login() {
  192.  }
  193.  @Override
  194.  public boolean onLongClick(View v) {
  195.   // TODO Auto-generated method stub
  196.   switch (v.getId()) {
  197.   case R.id.registfer:
  198.    if(SERVER_FLAG>9){
  199.     
  200.    }
  201.    //   SERVER_FLAG++;
  202.    break;
  203.   }
  204.   return true;
  205.  }
  206.  
  207.  /**
  208.   * 监听Back键按下事件,方法2:
  209.   * 注意:
  210.   * 返回值表示:是否能完全处理该事件
  211.   * 在此处返回false,所以会继续传播该事件.
  212.   * 在具体项目中此处的返回值视情况而定.
  213.   */ 
  214.  @Override 
  215.  public boolean onKeyDown(int keyCode, KeyEvent event) { 
  216.   if ((keyCode == KeyEvent.KEYCODE_BACK)) {
  217.    if(isReLogin){
  218.     Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);
  219.     mHomeIntent.addCategory(Intent.CATEGORY_HOME);
  220.     mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
  221.       | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
  222.     LoginActivity.this.startActivity(mHomeIntent);
  223.    }else{
  224.     LoginActivity.this.finish();
  225.    }
  226.    return false
  227.   }else { 
  228.    return super.onKeyDown(keyCode, event); 
  229.   } 
  230.  }
  231. }

转载于:https://my.oschina.net/zengliubao/blog/513753

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/705024
推荐阅读
相关标签
  

闽ICP备14008679号