直接上代码
private EditText edt; private CheckBox btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edt = (EditText) findViewById(R.id.edt); btn = (CheckBox) findViewById(R.id.btn); btn.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { // 设置EditText文本为可见的 edt.setTransformationMethod(HideReturnsTransformationMethod .getInstance()); } else { // 设置EditText文本为隐藏的 edt.setTransformationMethod(PasswordTransformationMethod .getInstance()); } edt.postInvalidate(); // 切换后将EditText光标置于末尾 CharSequence charSequence = edt.getText(); if (charSequence instanceof Spannable) { Spannable spanText = (Spannable) charSequence; Selection.setSelection(spanText, charSequence.length()); } } }); }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。