本文的demo和素材因为时间太久找不到了
另外一个登陆界面分享见:https://my.oschina.net/zengliubao/blog/841279
另外一个登陆界面分享见:https://my.oschina.net/zengliubao/blog/841279
-----------------------------------------------------------------------------------
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:custom="http://schemas.android.com/apk/res-auto"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:fitsSystemWindows="true" >
-
- <RelativeLayout
- android:id="@+id/login_layout"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp"
- android:gravity="center" >
- <FrameLayout
- android:id="@+id/username_layout"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="55dp"
- android:gravity="center" >
- <EditText
- android:id="@+id/username"
- android:layout_width="fill_parent"
- android:layout_height="@dimen/default_edittext_height"
- android:layout_marginTop="5dp"
- android:inputType="number"
- android:paddingRight="60dp"
- android:maxLength="20"
- android:paddingLeft="55dp" >
- </EditText>
- <ImageView
- android:layout_width="22dp"
- android:layout_height="21dp"
- android:layout_marginStart="8dp"
- android:layout_gravity="left|center_vertical"
- android:background="@drawable/login_usr_in_img"
- android:visibility="visible" />
- <TextView
- android:id="@+id/contry_sn"
- android:layout_width="40dp"
- android:layout_height="50dp"
- android:layout_gravity="left|center_vertical"
- android:layout_marginTop="4dp"
- android:gravity="center"
- android:text="+62"
- android:textColor="@android:color/black"
- android:textSize="18sp"
- android:visibility="invisible" />
-
- <Button
- android:id="@+id/bt_username_clear"
- android:layout_width="23dp"
- android:layout_height="23dp"
- android:background="@drawable/button_clear"
- android:layout_gravity="right|center_vertical"
- android:layout_marginRight="10dp"
- android:visibility="invisible"
- />
- </FrameLayout>
- <FrameLayout
- android:id="@+id/usercode_layout"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/username_layout"
- android:layout_marginTop="6dp"
- android:gravity="center" >
- <EditText
- android:id="@+id/password"
- android:layout_width="fill_parent"
- android:layout_height="@dimen/default_edittext_height" //40
- android:inputType="textPassword"
- android:paddingRight="60dp"
- android:maxLength="20"
- android:paddingLeft="55dp" >
- </EditText>
- <ImageView
- android:layout_width="24dp"
- android:layout_height="22dp"
- android:layout_marginStart="7dp"
- android:layout_gravity="left|center_vertical"
- android:background="@drawable/login_code_in_img" />
- <Button
- android:id="@+id/bt_pwd_eye"
- android:layout_width="23dp"
- android:layout_height="23dp"
- android:background="@drawable/button_eye_n"
- android:layout_gravity="right|center_vertical"
- android:layout_marginRight="10dp"
- />
- <Button
- android:id="@+id/bt_pwd_clear"
- android:layout_width="23dp"
- android:layout_height="23dp"
- android:background="@drawable/button_clear"
- android:visibility="invisible"
- android:layout_gravity="right|center_vertical"
- android:layout_marginRight="33dp"
- />
- </FrameLayout>
-
- <Button
- android:id="@+id/login"
- android:layout_width="fill_parent"
- android:layout_height="@dimen/default_button_height"
- android:layout_below="@id/usercode_layout"
- android:layout_marginTop="30dp"
- android:background="#ff336699"
- android:textColor="@android:color/white"
-
- android:gravity="center"
- android:text="登录" />
- <Button
- android:id="@+id/login_error"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignRight="@id/login"
- android:layout_below="@id/login"
- android:background="#00000000"
- android:text="忘记密码"
- android:textSize="16sp" />
- <Button
- android:id="@+id/register"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@id/login"
- android:layout_below="@id/login"
- android:background="#00000000"
- android:gravity="left|center_vertical"
- android:text="注册"
- android:textSize="16sp"
- android:visibility="visible" />
- </RelativeLayout>
- <RelativeLayout
- android:id="@+id/remember_layout000"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="1dp"
- android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp" >
- <Button
- android:id="@+id/registfer"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#00000000"
- android:gravity="center"
- android:singleLine="true"
- android:text="AnyLife,Make the world a better place."
- android:textSize="16sp"
- android:visibility="visible" />
- </RelativeLayout>
- </RelativeLayout>
- package com.bipbip.activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.text.Editable;
- import android.text.InputType;
- import android.text.TextWatcher;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.View.OnLongClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.bipbip.main.BaseActivity;
- import com.bipbip.main.MainActivity;
- import com.bipbip.watch.R;
-
- /**
- *
- *
- * 注 册: ValidatePhoneNumActivity --> RegisterActivity
- *
- * 忘记密码 ForgetCodeActivity --> RepasswordActivity
- *
- * @author liubao.zeng
- *
- */
- public class LoginActivity extends BaseActivity implements OnClickListener,OnLongClickListener {
- // 声明控件对象
- private EditText et_name, et_pass;
- private Button mLoginButton,mLoginError,mRegister,ONLYTEST;
- int selectIndex=1;
- int tempSelect=selectIndex;
- boolean isReLogin=false;
- private int SERVER_FLAG=0;
- private RelativeLayout countryselect;
- private TextView coutry_phone_sn, coutryName;//
- // private String [] coutry_phone_sn_array,coutry_name_array;
- public final static int LOGIN_ENABLE=0x01; //注册完毕了
- public final static int LOGIN_UNABLE=0x02; //注册完毕了
- public final static int PASS_ERROR=0x03; //注册完毕了
- public final static int NAME_ERROR=0x04; //注册完毕了
-
- final Handler UiMangerHandler = new Handler(){
- @Override
- public void handleMessage(Message msg) {
- // TODO Auto-generated method stub
- switch(msg.what){
- case LOGIN_ENABLE:
- mLoginButton.setClickable(true);
- // mLoginButton.setText(R.string.login);
- break;
- case LOGIN_UNABLE:
- mLoginButton.setClickable(false);
- break;
- case PASS_ERROR:
-
- break;
- case NAME_ERROR:
- break;
- }
- super.handleMessage(msg);
- }
- };
- private Button bt_username_clear;
- private Button bt_pwd_clear;
- private Button bt_pwd_eye;
- private TextWatcher username_watcher;
- private TextWatcher password_watcher;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // requestWindowFeature(Window.FEATURE_NO_TITLE);
- // //不显示系统的标题栏
- // getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
- // WindowManager.LayoutParams.FLAG_FULLSCREEN );
-
- setContentView(R.layout.activity_login);
- et_name = (EditText) findViewById(R.id.username);
- et_pass = (EditText) findViewById(R.id.password);
-
- bt_username_clear = (Button)findViewById(R.id.bt_username_clear);
- bt_pwd_clear = (Button)findViewById(R.id.bt_pwd_clear);
- bt_pwd_eye = (Button)findViewById(R.id.bt_pwd_eye);
- bt_username_clear.setOnClickListener(this);
- bt_pwd_clear.setOnClickListener(this);
- bt_pwd_eye.setOnClickListener(this);
- initWatcher();
- et_name.addTextChangedListener(username_watcher);
- et_pass.addTextChangedListener(password_watcher);
-
- mLoginButton = (Button) findViewById(R.id.login);
- mLoginError = (Button) findViewById(R.id.login_error);
- mRegister = (Button) findViewById(R.id.register);
- ONLYTEST = (Button) findViewById(R.id.registfer);
- ONLYTEST.setOnClickListener(this);
- ONLYTEST.setOnLongClickListener((OnLongClickListener) this);
- mLoginButton.setOnClickListener(this);
- mLoginError.setOnClickListener(this);
- mRegister.setOnClickListener(this);
-
- // countryselect=(RelativeLayout) findViewById(R.id.countryselect_layout);
- // countryselect.setOnClickListener(this);
- // coutry_phone_sn=(TextView) findViewById(R.id.contry_sn);
- // coutryName=(TextView) findViewById(R.id.country_name);
-
- // coutryName.setText(coutry_name_array[selectIndex]); //默认为1
- // coutry_phone_sn.setText("+"+coutry_phone_sn_array[selectIndex]);
- }
- /**
- * 手机号,密码输入控件公用这一个watcher
- */
- private void initWatcher() {
- username_watcher = new TextWatcher() {
- public void onTextChanged(CharSequence s, int start, int before, int count) {}
- public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
- public void afterTextChanged(Editable s) {
- et_pass.setText("");
- if(s.toString().length()>0){
- bt_username_clear.setVisibility(View.VISIBLE);
- }else{
- bt_username_clear.setVisibility(View.INVISIBLE);
- }
- }
- };
-
- password_watcher = new TextWatcher() {
- public void onTextChanged(CharSequence s, int start, int before, int count) {}
- public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
- public void afterTextChanged(Editable s) {
- if(s.toString().length()>0){
- bt_pwd_clear.setVisibility(View.VISIBLE);
- }else{
- bt_pwd_clear.setVisibility(View.INVISIBLE);
- }
- }
- };
- }
-
-
-
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- switch (arg0.getId()) {
- case R.id.login: //登陆
- // login();
- startActivity(MainActivity.class);
- break;
- case R.id.login_error: //无法登陆(忘记密码了吧)
- // Intent login_error_intent=new Intent();
- // login_error_intent.setClass(LoginActivity.this, ForgetCodeActivity.class);
- // startActivity(login_error_intent);
- break;
- case R.id.register: //注册新的用户
- // Intent intent=new Intent();
- // intent.setClass(LoginActivity.this, ValidatePhoneNumActivity.class);
- // startActivity(intent);
-
- break;
-
- case R.id.registfer:
- if(SERVER_FLAG>10){
- Toast.makeText(this, "[内部测试--谨慎操作]", Toast.LENGTH_SHORT).show();
- }
- SERVER_FLAG++;
- break;
- case R.id.bt_username_clear:
- et_name.setText("");
- et_pass.setText("");
- break;
- case R.id.bt_pwd_clear:
- et_pass.setText("");
- break;
- case R.id.bt_pwd_eye:
- if(et_pass.getInputType() == (InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD)){
- bt_pwd_eye.setBackgroundResource(R.drawable.button_eye_s);
- et_pass.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
- }else{
- bt_pwd_eye.setBackgroundResource(R.drawable.button_eye_n);
- et_pass.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
- }
- et_pass.setSelection(et_pass.getText().toString().length());
- break;
- }
- }
- /**
- * 登陆
- */
- private void login() {
- }
- @Override
- public boolean onLongClick(View v) {
- // TODO Auto-generated method stub
- switch (v.getId()) {
- case R.id.registfer:
- if(SERVER_FLAG>9){
-
- }
- // SERVER_FLAG++;
- break;
- }
- return true;
- }
-
-
- /**
- * 监听Back键按下事件,方法2:
- * 注意:
- * 返回值表示:是否能完全处理该事件
- * 在此处返回false,所以会继续传播该事件.
- * 在具体项目中此处的返回值视情况而定.
- */
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if ((keyCode == KeyEvent.KEYCODE_BACK)) {
- if(isReLogin){
- Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);
- mHomeIntent.addCategory(Intent.CATEGORY_HOME);
- mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
- LoginActivity.this.startActivity(mHomeIntent);
- }else{
- LoginActivity.this.finish();
- }
- return false;
- }else {
- return super.onKeyDown(keyCode, event);
- }
- }
-
- }