Android仿微信/支付宝的方块密码输入框

2024-06-04 12:58

本文主要是介绍Android仿微信/支付宝的方块密码输入框,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在用到支付类或者验证类app时,都有一个简密的输入框。百度了下有个不错的帖子   点击打开链接 

不过自己也写了个简单的类似的。不废话了。没图说个席八。


懒得运行,直接截layout.xml的效果图先。

布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="#ffffff"android:paddingBottom="20dp"android:paddingTop="30dp" ><TextViewandroid:id="@+id/txtTitle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:text="请输入验证码"android:textStyle="bold"android:textSize="22sp" /><LinearLayoutandroid:id="@+id/layout"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/txtTitle"android:layout_centerHorizontal="true"android:layout_marginTop="10dp"android:orientation="horizontal" ><TextViewandroid:id="@+id/t1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/i1"android:gravity="center"android:inputType="number"android:lines="1"android:maxLines="1" /><TextViewandroid:id="@+id/t2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/i1"android:gravity="center"android:inputType="number"android:lines="1"android:maxLines="1" /><TextViewandroid:id="@+id/t3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/i1"android:gravity="center"android:inputType="number"android:lines="1"android:maxLines="1" /><TextViewandroid:id="@+id/t4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/i2"android:gravity="center"android:inputType="number"android:lines="1"android:maxLines="1" /></LinearLayout><EditTextandroid:id="@+id/editHide"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBottom="@+id/layout"android:layout_alignLeft="@+id/layout"android:layout_alignRight="@+id/layout"android:layout_alignTop="@+id/layout"android:layout_weight="1"android:background="#00000000"android:cursorVisible="false"android:ems="10"android:inputType="number"android:maxLength="4"android:textColor="#00000000" /><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/layout"android:layout_centerHorizontal="true"android:layout_marginTop="20dp" ><Buttonandroid:id="@+id/verifycode_ok"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#fa8d70"android:layout_marginRight="30dp"android:textColor="#ffffff"android:text="确定" /><Buttonandroid:id="@+id/verifycode_cancel"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:background="@color/index_time_but"android:textColor="#ffffff"android:text="取消" /></LinearLayout></RelativeLayout>

代码:
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;public class MainActivity extends Activity {TextView t1, t2, t3, t4, et;String key = "";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.verifycode);t1 = (TextView) findViewById(R.id.t1);t2 = (TextView) findViewById(R.id.t2);t3 = (TextView) findViewById(R.id.t3);t4 = (TextView) findViewById(R.id.t4);et = (EditText) findViewById(R.id.editText1);et.addTextChangedListener(tw);}void setKey() {char[] arr = key.toCharArray();t1.setText("");t2.setText("");t3.setText("");t4.setText("");for (int i = 0; i < arr.length; i++) {if (i == 0) {t1.setText(String.valueOf(arr[0]));} else if (i == 1) {t2.setText(String.valueOf(arr[1]));} else if (i == 2) {t3.setText(String.valueOf(arr[2]));} else if (i == 3) {t4.setText(String.valueOf(arr[3]));}}}TextWatcher tw = new TextWatcher() {@Overridepublic void onTextChanged(CharSequence s, int start, int before,int count) {}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {}@Overridepublic void afterTextChanged(Editable s) {key = s.toString();setKey();}};
}

好哒。就这样了。运行就有效果了。没有什么自定义,没有什么第三方。


当然。如果你要弹窗形式的话,也一样,加下面的就能弹窗了

	final AlertDialog dialog = new AlertDialog.Builder(mContext).create();dialog.show();dialog.getWindow().setContentView(R.layout.verifycode);t1 = (TextView) dialog.findViewById(R.id.t1);t2 = (TextView) dialog.findViewById(R.id.t2);t3 = (TextView) dialog.findViewById(R.id.t3);t4 = (TextView) dialog.findViewById(R.id.t4);

后期有时间再补上项目DOME。下班。走人


这篇关于Android仿微信/支付宝的方块密码输入框的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1030150

相关文章

Eclipse+ADT与Android Studio开发的区别

下文的EA指Eclipse+ADT,AS就是指Android Studio。 就编写界面布局来说AS可以边开发边预览(所见即所得,以及多个屏幕预览),这个优势比较大。AS运行时占的内存比EA的要小。AS创建项目时要创建gradle项目框架,so,创建项目时AS比较慢。android studio基于gradle构建项目,你无法同时集中管理和维护多个项目的源码,而eclipse ADT可以同时打开

android 免费短信验证功能

没有太复杂的使用的话,功能实现比较简单粗暴。 在www.mob.com网站中可以申请使用免费短信验证功能。 步骤: 1.注册登录。 2.选择“短信验证码SDK” 3.下载对应的sdk包,我这是选studio的。 4.从头像那进入后台并创建短信验证应用,获取到key跟secret 5.根据技术文档操作(initSDK方法写在setContentView上面) 6.关键:在有用到的Mo

android一键分享功能部分实现

为什么叫做部分实现呢,其实是我只实现一部分的分享。如新浪微博,那还有没去实现的是微信分享。还有一部分奇怪的问题:我QQ分享跟QQ空间的分享功能,我都没配置key那些都是原本集成就有的key也可以实现分享,谁清楚的麻烦详解下。 实现分享功能我们可以去www.mob.com这个网站集成。免费的,而且还有短信验证功能。等这分享研究完后就研究下短信验证功能。 开始实现步骤(新浪分享,以下是本人自己实现

Android我的二维码扫描功能发展史(完整)

最近在研究下二维码扫描功能,跟据从网上查阅的资料到自己勉强已实现扫描功能来一一介绍我的二维码扫描功能实现的发展历程: 首页通过网络搜索发现做android二维码扫描功能看去都是基于google的ZXing项目开发。 2、搜索怎么使用ZXing实现自己的二维码扫描:从网上下载ZXing-2.2.zip以及core-2.2-source.jar文件,分别解压两个文件。然后把.jar解压出来的整个c

android 带与不带logo的二维码生成

该代码基于ZXing项目,这个网上能下载得到。 定义的控件以及属性: public static final int SCAN_CODE = 1;private ImageView iv;private EditText et;private Button qr_btn,add_logo;private Bitmap logo,bitmap,bmp; //logo图标private st

Android多线程下载见解

通过for循环开启N个线程,这是多线程,但每次循环都new一个线程肯定很耗内存的。那可以改用线程池来。 就以我个人对多线程下载的理解是开启一个线程后: 1.通过HttpUrlConnection对象获取要下载文件的总长度 2.通过RandomAccessFile流对象在本地创建一个跟远程文件长度一样大小的空文件。 3.通过文件总长度/线程个数=得到每个线程大概要下载的量(线程块大小)。

vue+elementui分页输入框回车与页面中@keyup.enter事件冲突解决

解决这个问题的思路只要判断事件源是哪个就好。el分页的回车触发事件是在按下时,抬起并不会再触发。而keyup.enter事件是在抬起时触发。 so,找不到分页的回车事件那就拿keyup.enter事件搞事情。只要判断这个抬起事件的$event中的锚点样式判断不等于分页特有的样式就可以了 @keyup.enter="allKeyup($event)" //页面上的//js中allKeyup(e

时间服务器中,适用于国内的 NTP 服务器地址,可用于时间同步或 Android 加速 GPS 定位

NTP 是什么?   NTP 是网络时间协议(Network Time Protocol),它用来同步网络设备【如计算机、手机】的时间的协议。 NTP 实现什么目的?   目的很简单,就是为了提供准确时间。因为我们的手表、设备等,经常会时间跑着跑着就有误差,或快或慢的少几秒,时间长了甚至误差过分钟。 NTP 服务器列表 最常见、熟知的就是 www.pool.ntp.org/zo

高仿精仿愤怒的小鸟android版游戏源码

这是一款很完美的高仿精仿愤怒的小鸟android版游戏源码,大家可以研究一下吧、 为了报复偷走鸟蛋的肥猪们,鸟儿以自己的身体为武器,仿佛炮弹一样去攻击肥猪们的堡垒。游戏是十分卡通的2D画面,看着愤怒的红色小鸟,奋不顾身的往绿色的肥猪的堡垒砸去,那种奇妙的感觉还真是令人感到很欢乐。而游戏的配乐同样充满了欢乐的感觉,轻松的节奏,欢快的风格。 源码下载

Android SurfaceFlinger——图形内存分配器(十一)

前面的文章中的图层合成器(HWC),这里我们接着看一下 SurfaceFlinger 中的另一个重要服务——图形内存分配器。 一、简介         android.hardware.graphics.allocator@2.0 是 Android 系统中硬件抽象层(HAL)的一个组件,专门用于图形内存的分配和管理。它是 SurfaceFlinger 在处理图形数据时所依赖的