通过设置EditText的setTransformationMethod()方法来实现隐藏密码或这显示密码,示例如下:
private Button mBtnPassword;
private EditText mEtPassword;
private boolean mbDisplayFlg = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mEtPassword = (EditText)findViewById(R.id.password);
mBtnPassword = (Button)findViewById(R.id.btnPassword);
mBtnPassword.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("AndroidTest", "mbDisplayFlg = " + mbDisplayFlg);
if (!mbDisplayFlg) {
// display password text, for example "123456"
mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
// hide password, display "."
mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
mbDisplayFlg = !mbDisplayFlg;
mEtPassword.postInvalidate();
}
});
}
main.xml
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
你说的小眼睛是 隐藏和显示输入框的内容吗?可以根据状态设置显示的内容啊
点一下改变一下文本框的属性就好了