EditText为空时提示方法:
1.xml文件中设置,如:android:hint="@string/user_name"
2.如:定义EditText变量mUserNamet,mUserName.setHint("昵称");
EditText密码隐藏:
//判断密码是否为空,做不同的操作
if(密码为空){
mUserPassword.setHint("密码");
mUserPassword.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);}
else{
mUserPassword.setInputType
(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
mUserPassword.setText(suserPassword);}
//监听密码输入情况,做不同的操作
mUserPassword.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
Editable etable = mUserPassword.getText();
mUserPassword.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);
mUserPassword.setSelection(etable.length());//设置光标总是在最后,这点很重要
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
});
1.xml文件中设置,如:android:hint="@string/user_name"
2.如:定义EditText变量mUserNamet,mUserName.setHint("昵称");
EditText密码隐藏:
//判断密码是否为空,做不同的操作
if(密码为空){
mUserPassword.setHint("密码");
mUserPassword.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);}
else{
mUserPassword.setInputType
(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
mUserPassword.setText(suserPassword);}
//监听密码输入情况,做不同的操作
mUserPassword.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
Editable etable = mUserPassword.getText();
mUserPassword.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);
mUserPassword.setSelection(etable.length());//设置光标总是在最后,这点很重要
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
});