Android实现密码隐藏和显示
本文实例为大家分享了Android实现密码隐藏和显示的具体代码,供大家参考,具体内容如下
在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法:
xml代码:
<LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/white" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:text="新密码" android:textColor="@color/black" android:textSize="18dp" android:gravity="center_vertical" android:layout_marginLeft="15dp"/> <EditText android:id="@+id/newpassword" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:layout_marginLeft="10dp" android:inputType="textPassword" android:hint="请设置登录密码" android:background="@null"/> <CheckBox android:id="@+id/CheckBox" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginRight="15dp" android:textSize="16dp" android:text="显示" /> </LinearLayout>
####隐藏图标代码
android:button="@null"
JAVA代码:
/** * Created by fby on 2017/9/11. */ public class ChargepsdActivity extends Activity { private EditText editText; private CheckBox checkBox; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chargepsd); editText = (EditText) findViewById(R.id.newpassword); checkBox = (CheckBox) findViewById(R.id.CheckBox); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ //如果选中,显示密码 editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); }else{ //否则隐藏密码 editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } }); } }
效果展示:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Android中AutoCompleteTextView与TextWatcher结合小实例
这篇文章主要为大家详细介绍了Android中AutoCompleteTextView与TextWatcher结合的小实例,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-05-05Android带刷新时间显示的PullToRefresh上下拉刷新
这篇文章主要为大家详细介绍了Android带刷新时间显示的PullToRefresh上下拉刷新,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2018-12-12Android HorizontalScrollView内子控件横向拖拽实例代码
本文主要介绍Android HorizontalScrollView的使用,这里给大家一个实例来展示HorizontalScrollView内子控件横向拖拽的效果实现,有需要的小伙伴可以参考下2016-07-07解决java.lang.NoClassDefFoundError: android.support.v4.animati
这篇文章主要介绍了解决Android Studio出现java.lang.NoClassDefFoundError: android.support.v4.animation.AnimatorCompatHelper的问题,感兴趣的朋友一起看看吧2021-08-08Android编程基于Contacts读取联系人的方法(附demo源码)
这篇文章主要介绍了Android编程基于Contacts读取联系人的方法,实例分析了Contacts读取的实现方法及权限设置方法,并附带了完整实例供读者下载参考,需要的朋友可以参考下2015-12-12
最新评论