- 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 发布