EditText设置密码隐藏和显示
2017-04-17 14:44
453 查看
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="liu.basedemo.MainActivity"> <EditText android:id="@+id/etUsername" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp" android:hint="请输入用户名" android:textColor="#000000" android:textColorHint="#55000000" android:textSize="20sp"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <EditText android:id="@+id/etPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp" android:hint="请输入密码" android:inputType="textPassword" android:textColor="#000000" android:textColorHint="#55000000" android:textSize="20sp"/> <CheckBox android:checked="false" android:id="@+id/cbDisplayPassword" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:button="@drawable/selector_password"/> </RelativeLayout> </LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@mipmap/cb_checked" android:state_checked="true"/><item android:drawable="@mipmap/cb_normaled" android:state_checked="false"/></selector>
第一种方式
private void initListener() {mCbDisplayPassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {Log.d(TAG, "onCheckedChanged: "+isChecked);if(isChecked){//选择状态 显示明文--设置为可见的密码mEtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);}else {//默认状态显示密码--设置文本 要一起写才能起作用 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORDmEtPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);}}});}
第二种方式
private void initListener() {mCbDisplayPassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {Log.d(TAG, "onCheckedChanged: "+isChecked);if(isChecked){//选择状态 显示明文--设置为可见的密码//mEtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);/*** 第二种*/mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());}else {//默认状态显示密码--设置文本 要一起写才能起作用 InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD//mEtPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);/*** 第二种*/mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());}}});}
相关文章推荐
- Android中设置EditText显示或隐藏密码
- 设置EditText显示或隐藏密码
- 设置editText显示或隐藏密码
- EditText设置密码显示明文及隐藏切换
- EditText设置点击按钮显示与隐藏密码
- 动态设置EditText密码的显示和隐藏
- 代码中设置EditText显示或者隐藏密码
- Android中设置EditText显示或隐藏密码
- Android 设置EditText显示或隐藏密码
- editText设置密码隐藏和显示
- Android EditText 显示或隐藏密码,增加边框,设置光标操作
- Android:EditText中切换密码的显示与隐藏
- Android EditText控制密码的显示和隐藏
- Android完美解决输入框EditText隐藏密码打勾显示密码问题
- EditText实现显示和隐藏密码
- Android文本输入框(EditText)输入密码时显示与隐藏
- Android UI设计 文本输入框EditText用法(输入密码 隐藏显示输入的字符串)
- 两种方法,针对EditText密码的显示和隐藏(包括激将光标移动到文本末尾)
- (七十三)Android 设置EditText光标颜色及粗细 和设定EditText的光标为显示/隐藏
- 动态修改EditText输入键盘并隐藏或显示密码