密码框显示和隐藏
- import android.app.Activity;
- import android.graphics.Rect;
- import android.os.Bundle;
- import android.text.method.HideReturnsTransformationMethod;
- import android.text.method.PasswordTransformationMethod;
- import android.text.method.TransformationMethod;
- import android.view.View;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.CompoundButton.OnCheckedChangeListener;
- import android.widget.EditText;
- public class PasswordIsShowTestActivity extends Activity {
- private EditText username;
- private EditText password;
- private CheckBox cbBox ;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- username = (EditText)findViewById(R.id.editText1);
- password = (EditText)findViewById(R.id.editText2);
- cbBox = (CheckBox)findViewById(R.id.checkBox1);
- cbBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if(cbBox.isChecked()){
- password.setTransformationMethod(
- HideReturnsTransformationMethod.getInstance());
- }else{
- password.setTransformationMethod(
- PasswordTransformationMethod.getInstance());
- }
- }
- });
- }
- }
android 技术交流QQ群:108614806