您的位置:首页 > 移动开发 > Android开发

Android之QQ登录界面

2016-09-01 00:22 344 查看
[b][b]

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">qqloginnew</string>
<string name="action_settings">Settings</string>
<string name="button">登录</string>
<string name="faillogin">无法登录?</string>
<string name="regist">新用户注册</string>
<string name="inaccount">QQ号/手机号/邮箱</string>
<string name="inpwd">密码</string>
<string name="sucess">登录成功</string>

</resources>


strings
MainActivity (问题3、4.....)

package com.dragon.android.qqloginnew;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
private EditText editText1;
private EditText editText2;
// private Button button;
private Button clearButton1;
private Button clearButton2;

// 得到strings中的属性
// private String string2 = getResources().getString(R.string.inaccount);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);

editText1 = (EditText) findViewById(R.id.editText1);
editText2 = (EditText) findViewById(R.id.editText2);

// button = (Button) findViewById(R.id.button1);
clearButton1 = (Button) findViewById(R.id.button2);
clearButton2 = (Button) findViewById(R.id.button3);

// 对EditText进行焦点变更监听
editText1.setOnFocusChangeListener(new EditTextListener(clearButton1));
editText2.setOnFocusChangeListener(new EditTextListener(clearButton2));

// 对清空按钮进行点击监听
clearButton1.setOnClickListener(new ClearButtonListener());
clearButton2.setOnClickListener(new ClearButtonListener());

// 对EditText进行编辑监听
editText1.addTextChangedListener(new MyEditTextWatcher(editText1));
editText2.addTextChangedListener(new MyEditTextWatcher(editText2));
}

/**
* 对EditText的内容进行实时监控
*
* @author Auser
*
*/
class MyEditTextWatcher implements TextWatcher {
private CharSequence temp;
private EditText editText;

public MyEditTextWatcher(EditText editText) {
this.editText = editText;
}

@Override
// int start开始的位置, int count被改变的旧内容数, int after改变后的内容数量
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// 这里的s表示改变之前的内容,通常start和count组合,可以在s中读取本次改变字段中被改变的内容。而after表示改变后新的内容的数量。
}

@Override
// int start开始的位置, int before改变前的内容数量, int count新增量
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// 这里的s表示改变之后的内容,通常start和count组合,可以在s中读取本次改变字段中新的内容。而before表示被改变的内容的数量。
temp = s;
}

@Override
// 表示最终内容
public void afterTextChanged(Editable s) {
if (temp.length() > 0) {
// 设置清空按钮为可见
if (editText == editText1) {
clearButton1.setVisibility(View.VISIBLE);
} else if (editText == editText2) {
clearButton2.setVisibility(View.VISIBLE);
}
} else {
// 设置清空按钮不可见
if (editText == editText1) {
clearButton1.setVisibility(View.INVISIBLE);
} else if (editText == editText2) {
clearButton2.setVisibility(View.INVISIBLE);
}
}
}
}

/**
* 清空按钮点击事件
*
* @author
*
*/
class ClearButtonListener implements OnClickListener {

@Override
public void onClick(View view) {
if (view == clearButton1) {
editText1.setText("");
} else if (view == clearButton2) {
editText2.setText("");
}
}
}

/**
* 焦点变更事件
*
* @author Auser
*
*/
class EditTextListener implements OnFocusChangeListener {
private Button clear;

public EditTextListener(Button clear) {
this.clear = clear;
}

@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText textView = (EditText) v;
String hint;
if (hasFocus) {
// 当获取焦点时如果内容不为空则清空按钮可见
if (!textView.getText().toString().equals("")) {
clear.setVisibility(View.VISIBLE);
}
// if (textView == editText2) {
// // 设置输入格式为不可见的密码格式
// textView.setInputType(InputType.TYPE_CLASS_TEXT
// | InputType.TYPE_TEXT_VARIATION_PASSWORD);
// }
hint = textView.getHint().toString();
// 给TextView添加额外的数据
textView.setTag(hint);
textView.setHint("");
} else {
// 当失去焦点时清空按钮不可见
clear.setVisibility(View.INVISIBLE);
// if (textView == editText2) {
// // 设置输入格式为可见的密码格式
// textView.setInputType(InputType.TYPE_CLASS_TEXT
// | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
// }
// 取出之前添加的额外数据
hint = textView.getTag().toString();
textView.setHint(hint);
}
}
}
}


图片素材

a.png

clear.png


-------------------------一个初步的登录界面------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: