- public class ShowpasswordActivity extends Activity {
- EditText password;
- CheckBox showcheck;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- password = (EditText)this.findViewById(R.id.password);
- showcheck = (CheckBox)this.findViewById(R.id.showcheck);
-
- //CheckBoxe的事件监听
- show.setOnCheckedChangeListener(new OnCheckedChangeListener(){
- @Override
- public void onCheckedChanged(CompoundButton buttonView,
- boolean isChecked) {
- if(isChecked) {//设置成明文
- password.setTransformationMethod
- (HideReturnsTransformationMethod.getInstance());
- } else {//设置成密文
- password.setTransformationMethod
- (PasswordTransformationMethod.getInstance());
- }
- }
- });
- }
- }
Android中EditTex的密文和明文切换
最新推荐文章于 2022-02-11 17:16:00 发布
本文介绍了一个简单的Android应用示例,该应用使用CheckBox控制密码输入框的可见性,实现在明文与密文间的切换。通过为CheckBox设置OnCheckedChangeListener监听器,根据CheckBox的状态改变EditText的TransformationMethod,从而达到密码显示与隐藏的效果。
402

被折叠的 条评论
为什么被折叠?



