在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法:
创新互联-专业网站定制、快速模板网站建设、高性价比兴国网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式兴国网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖兴国地区。费用合理售后完善,10余年实体公司更值得信赖。
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中实现密码的隐藏和显示的示例
文章地址:https://www.cdcxhl.com/article10/phocdo.html
成都网站建设公司_创新互联,为您提供关键词优化、外贸网站建设、云服务器、软件开发、面包屑导航、网站策划
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联