demo: Android中EditText密码样式设置
package com.example.preferencescreen; import android.app.Activity; import android.os.Bundle; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; public class PasswordActivity extends Activity { private EditText ed; private CheckBox cb; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.password); ed = (EditText) findViewById(R.id.editText1); cb = (CheckBox) findViewById(R.id.checkBox1); cb.setChecked(false); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { // TODO Auto-generated method stub if (cb.isChecked()) <span style="white-space:pre"> </span>//显示密码 ed.setTransformationMethod(HideReturnsTransformationMethod .getInstance()); else <span style="white-space:pre"> </span>//隐藏密码 ed.setTransformationMethod(PasswordTransformationMethod .getInstance()); } }); } }