setTransformationMethod 的使用 – 热爱改变生活
我的GitHub GitHub |     登录
  • If you can't fly, then run; if you can't run, then walk; if you can't walk, then crawl
  • but whatever you do, you have to keep moving forward。
  • “你骗得了我有什么用,这是你自己的人生”
  • 曾有伤心之地,入梦如听 此歌

setTransformationMethod 的使用

Android sinvader 15692℃ 0评论

setTransformationMethod 的使用

1. 点击一个控件隐藏/显示 EditText 中的密码

  1. final CheckBox checkbox = (CheckBox) findViewById(R.id.cb);
  2. /* add a listener to the CheckBox */
  3. checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
  4. public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
  5. if(checkbox.isChecked()){
  6. /* show the password*/
  7. textCarNumberNear.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
  8. }
  9. else{
  10. /* hide the password */
  11. textCarNumberNear.setTransformationMethod(PasswordTransformationMethod.getInstance());
  12. }
  13. }
  14. });

也可以使用:

  1. if(isChecked){
  2. //显示密码框内容
  3. mEditPwd.setInputType(InputType.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_NORMAL);
  4. }else{
  5. //隐藏密码框内容
  6. mEditPwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  7. }
  8. mEditPwd.setSelection(mEditPwd.getText().toString().length());//设置光标位置在文本框末尾

 

2:

这个里面是用来将输入到 EditText 中的小写字母转化为大写字母的

  1. //----------------小写转化为大写--------------------------//
  2. public class InputLowerToUpper extends ReplacementTransformationMethod{
  3. @Override
  4. protected char[] getOriginal() {
  5. char[] lower = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
  6. return lower;
  7. }
  8. @Override
  9. protected char[] getReplacement() {
  10. char[] upper = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
  11. return upper;
  12. }
  13. }

 

下面是使用的代码

  1. final EditText textCarNumber=(EditText) viewNew.findViewById(R.id.borrow_carnumber);
  2. textCarNumber.setTransformationMethod(new InputLowerToUpper());
¥ 有帮助么?打赏一下~

转载请注明:热爱改变生活.cn » setTransformationMethod 的使用


本博客只要没有注明“转”,那么均为原创。 转载请注明链接:sumile.cn » setTransformationMethod 的使用

喜欢 (4)
发表我的评论
取消评论
表情

如需邮件形式接收回复,请注册登录

Hi,你需要填写昵称和邮箱~

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址