Android自定义键盘与密码输入框:使用BasicUI库的简单实现

一、前言


BasicUI是一些常用的Android UI组件和一些实用工具类封装,提高Android的开发效率

使用文档链接:github.com/Peakmain/Ba...

How to

  • Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

rust 复制代码
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
  • Step 2. Add the dependency
arduino 复制代码
implementation 'com.github.Peakmain:BasicUI:+'
  • Step 3.some probleam

    如果你的gradle版本比3.5.3高,可能会出现以下几个问题:

    1、Entry name 'AndroidManifest.xml' collided

    解决办法:在gradle.properties添加以下代码

    ini 复制代码
    android.useNewApkCreator=false

    2、如果安装失败,用adb install安装报错提示如下

    failed to install app-debug.apk: Failure [INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: Failed to parse /data/app/vmdl1335956833.tmp/base.apk: Corrupt XML binary file]

    解决办法:在添加依赖的build.gradle中添加以下代码

    arduino 复制代码
      android{
           packagingOptions {
            exclude 'AndroidManifest.xml'
         }
       }

二、自定义键盘

效果图

使用

xml 复制代码
        <com.peakmain.ui.widget.password.PasswordEditText
            android:id="@+id/password_edit_text"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimen_50"
            android:layout_marginLeft="@dimen/dimen_17"
            android:layout_marginRight="@dimen/dimen_17"
            android:layout_marginBottom="@dimen/dimen_16"
            app:bgColor="@color/color_f1f4f6"
            app:bgCorner="@dimen/dimen_4"
            app:layout_constraintBottom_toTopOf="@id/tv_show_password"
            app:passwordColor="@color/black" />

自定义属性说明

属性名 属性类型 描述
ckExtraKey String 是否显示身份证信息,true表示显示
ckDecimalPlaces integer 小数点后几位
ckShowKeyBroad boolean 是否显示小数点

方法说明

方法名 方法返回类型 描述
setOnCustomerKeyboardClickListener void 自定义点击事件,有三个方法实现:①、click(number: String?)点击事件;②、delete():删除事件、③、dissmiss():键盘隐藏事件

示例代码

支付密码键盘
xml 复制代码
        <com.peakmain.ui.widget.password.CustomerKeyboard
            android:id="@+id/custom_key_board"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent" />
身份证键盘
xml 复制代码
        <com.peakmain.ui.widget.password.CustomerKeyboard
            android:id="@+id/custom_key_board"
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            app:ckExtraKey="X"
            android:layout_height="wrap_content" />
小数点键盘
xml 复制代码
        <com.peakmain.ui.widget.password.CustomerKeyboard
            android:id="@+id/custom_key_board"
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            app:ckExtraKey="."
            app:ckDecimalPlaces="3"
            android:layout_height="wrap_content" />

三、自定义密码输入框

效果图

属性说明

属性名 属性类型 描述
passwordNumber integer 密码的个数
passwordRadius dimension 密码圆点的半径
passwordColor color 密码圆点的颜色
divisionLineColor color 分割线的颜色
divisionLineSize dimension 分割线的大小
bgColor color 背景边框的颜色
bgSize dimension 背景边框的大小
bgCorner dimension 背景边框的圆角大小
bgFillColor color 背景的填充颜色

方法说明

方法名 方法返回值类型 描述
addPasswordNumber void 添加密码
deletePassWord void 删除密码
setPasswordCompleteListener void 设置密码输入完成事件
setPasswordVisible void 设置密码是否可见
isPasswordVisible void 判断密码是否可见

示例

  • 布局
xml 复制代码
        <com.peakmain.ui.widget.password.PasswordEditText
            android:id="@+id/password_edit_text"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimen_50"
            android:layout_marginLeft="@dimen/dimen_17"
            android:layout_marginRight="@dimen/dimen_17"
            android:layout_marginBottom="@dimen/dimen_16"
            app:bgColor="@color/color_f1f4f6"
            app:bgCorner="@dimen/dimen_4"
            app:layout_constraintBottom_toTopOf="@id/tv_show_password"
            app:passwordColor="@color/black" />
  • 设置密码输入完成监听回调事件
kotlin 复制代码
      mEditText!!.setPasswordCompleteListener { text: String -> ToastUtils.showShort(text) }
相关推荐
恋猫de小郭1 小时前
Flutter 在 Dart 3.8 开始支持 Null-Aware Elements 语法,自动识别集合里的空元素
android·前端·flutter
fatiaozhang95272 小时前
咪咕MG101_晨星MSO9380芯片_安卓5.1.1_免拆卡刷固件包
android·电视盒子·av1·机顶盒rom·魔百盒刷机
_小马快跑_3 小时前
玩转 ImageView.ScaleType:图片的缩放与裁剪技巧
android
Lei活在当下3 小时前
【现代 Android APP 架构】02. UI 层的职责与具体实现
android·架构·android jetpack
_一条咸鱼_3 小时前
揭秘 Android 高级工程师面试秘籍:从源码到实战全方位剖析
android·面试·android jetpack
_一条咸鱼_3 小时前
深度揭秘!从源码级剖析 Android 基础知识体系
android·面试·android jetpack
_小马快跑_3 小时前
Android Studio | 使用Database Inspector 查看数据库 .db 文件,太方便了!
android
snwrking3 小时前
[targetSDK升级为35] 恶心的EdgeToEdge适配
android
QING6183 小时前
AndroidManifest.xml中application标签属性详解 —— 新手指南
android·app·trae