当前位置: 首页 > news >正文

简单实现支付密码的页面及输入效果

干我们这行,风吹日晒不到,就怕甲方突发奇想。
今天客户要做一个安全密码前置校验,还要做成支付宝那种效果。ps:android端
心理吐槽了一万遍以后,还是得面对现实。
先用通义问一遍,给了两个方案,要么自己写,要么用第三方库。
向来自己动手的我,先试着把通义给的源码抄下来,运行效果不佳。
转用第三方库,sync后版本又不对,找了多个库,效果都不理想,要么版本不兼容,要么效果不理想。
最后回头用通义的思路自己写。
思路分为三个步骤。
1.页面上用6个textview,用来显示黑点的效果,外加一个edittext,edittext宽高1dp,基本是隐藏的效果,edittext用来接受焦点和输入密码

 		<LinearLayoutandroid:id="@+id/ll_password"android:layout_width="match_parent"android:layout_height="50dp"android:orientation="horizontal"  ><TextView android:id="@+id/tv1" style="@style/PwdBox" /><TextView android:id="@+id/tv2" style="@style/PwdBox" /><TextView android:id="@+id/tv3" style="@style/PwdBox" /><TextView android:id="@+id/tv4" style="@style/PwdBox" /><TextView android:id="@+id/tv5" style="@style/PwdBox" /><TextView android:id="@+id/tv6" style="@style/PwdBox" /></LinearLayout><EditText android:id="@+id/password_input"android:inputType="number"android:maxLength="6"android:layout_width="match_parent"android:layout_height="1dp"></EditText>

2.点击textview,使edittext获取焦点,但是无法拉起输入键盘,要单独写拉起键盘的操作。

password_input.requestFocus();
showime();
private void showime(){InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);if (imm != null) {imm.showSoftInput(password_input, InputMethodManager.SHOW_IMPLICIT);}}

3.键盘输入后,假密码框有输入效果

TextWatcher commonTextWatcher = new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic void afterTextChanged(Editable s) { Log.d("EditText", "内容变化: " + s.toString());String password=s.toString();for(int i=0;i<tvs.length;i++) {tvs[i].setText("");}for(int i=0;i<password.length();i++) {tvs[i].setText("●");}if(password.length()==6  ){if(password.equals("000000")){ //方便书写,应该通过接口验证hideime(); //隐藏键盘}else{//未通过验证的处理逻辑}}}};password_input.addTextChangedListener(commonTextWatcher);
 private void hideime(){InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);System.out.println(getCurrentFocus());if (imm != null && getCurrentFocus() != null) {imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);}}

这样就搞定了,这个思路可以用到各个开发语言下。这个只是思路,具体实现还要补充不少东西。看下效果
在这里插入图片描述

http://www.lryc.cn/news/600627.html

相关文章:

  • Sql server查询汇总补缺月份
  • 【iOS】网易云仿写
  • 基于深度学习的胸部 X 光图像肺炎分类系统(七)
  • springboot 前后端,基于票据+SHA派生密钥+SM4加解密
  • 经典IDE之Turbo C
  • 基于MC9S12XEP100的整车控制器(VCU)设计
  • 【Zephyr】Window下的Zephyr编译和使用
  • Redis的数据淘汰策略是什么?有哪些?
  • 资产负债表及其数据获取
  • 【LeetCode 热题 100】79. 单词搜索——回溯
  • 进阶数据结构:用红黑树实现封装map和set
  • element-plus安装以及使用
  • 机器人仿真(2)Ubuntu24.04下RTX5090配置IsaacSim与IsaacLab
  • Java实现大根堆与小根堆详解
  • 【数据结构】栈和队列的实现
  • 基于DataX的数据同步实战
  • 详解力扣高频SQL50题之1141. 查询近30天活跃用户数【简单】
  • STM32-定时器的基本定时/计数功能实现配置教程(寄存器版)
  • 手动开发一个串口调试工具(二):Qt 串口类基本认识与使用
  • ClickHouse高性能实时分析数据库-消费实时数据流(消费kafka)
  • 【Linux系统】理解硬件 | 引入文件系统
  • Kotlin线程同步
  • 高并发微服务限流算法方案对比与实践指南
  • 告别Vite脚手架局限!MixOne Beta测试招募:你的需求,我们来实现
  • 基于 ThinkPHP 开发的垂直化网址导航
  • 深入解析Hadoop如何实现数据可靠性:三副本策略、校验和验证与Pipeline复制
  • 使用Spring Boot创建Web项目
  • Java 大视界 -- Java 大数据在智能安防视频监控系统中的视频语义理解与智能检索进阶(365)
  • 【工程化】浅谈前端构建工具
  • nginx一个域名下部署多套前端项目