A clean, minimal, highly customizable pin lock view for Android
PinLockView
一款简洁、极简风格、易于使用且高度可定制的 Android 密码锁自定义视图。
规格

此库允许您在应用中轻松且快速地实现密码锁机制。提供了众多定制选项,可根据应用主题更改此视图的外观和感觉。
您还可以将其用作拨号盘来拨打号码。这个库还有许多其他用途,不仅限于密码锁定。

下载
此库可在jCenter上获取,这是 Android Studio 默认使用的 Maven 仓库。
Gradle
dependencies {
// other dependencies here
implementation 'com.andrognito.pinlockview:pinlockview:2.1.0'
}
Maven
Maven 是一个项目管理和构建自动化工具,主要用于 Java 项目。它能够帮助开发者自动化构建过程,管理项目依赖,以及简化项目的配置。Maven 使用基于 XML 的配置文件 pom.xml 来管理项目的构建过程和依赖关系。通过定义项目对象模型(POM),Maven 能够为项目提供一套标准化的构建生命周期,包括编译、测试、打包、部署等阶段。这使得开发者能够集中精力在代码开发上,而无需过多关注构建过程的具体细节。
<dependency>
<groupId>com.andrognito.pinlockview</groupId>
<artifactId>pinlockview</artifactId>
<version>2.1.0</version>
<type>pom</type>
</dependency>
使用说明
我们建议您查看示例应用,以获得对库的全面了解。以下是逐步实现指南。
第一步
在您的 XML 布局文件中放置视图。
<com.andrognito.pinlockview.PinLockView
android:id="@+id/pin_lock_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
步骤 2
在代码中引用视图并为其添加监听器。
mPinLockView = (PinLockView) findViewById(R.id.pin_lock_view);
mPinLockView.setPinLockListener(mPinLockListener);
以下是根据要求实现的监听器接口:
private PinLockListener mPinLockListener = new PinLockListener() {
@Override
public void onComplete(String pin) {
Log.d(TAG, "Pin complete: " + pin);
}
@Override
public void onEmpty() {
Log.d(TAG, "Pin empty");
}
@Override
public void onPinChange(int pinLength, String intermediatePin) {
Log.d(TAG, "Pin changed, new length " + pinLength + " with intermediate pin " + intermediatePin);
}
};
简而言之!您的 PinLockView 已经准备就绪,可以大显身手了。
但好消息是,PinLockView 提供了丰富的自定义选项,让您能够按需对视图进行任何方式的个性化定制。
自定义
指示点(附加组件)
PinLockView 随附了一个附加视图组件 —— IndicatorDots,它可以选择性地与 PinLockView 配合使用,以向用户视觉化地显示密码变化。
这个 视图已经被从 PinLockView 中解耦,因此您可以根据需要选择性地添加它。假设您正在实现一个拨号盘,那么显然您就不需要这个指示视图。
将视图添加到您的 XML 布局中,通常放置在 PinLockView 的上方,
<com.andrognito.pinlockview.IndicatorDots
android:id="@+id/indicator_dots"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
然后寻找视图的引用并将其附着到父级 PinLockView 上,
mIndicatorDots = (IndicatorDots) findViewById(R.id.indicator_dots);
mPinLockView.attachIndicatorDots(mIndicatorDots);
您必须将其附加到 PinLockView 上,否则它将不会被理会。
主题定制
通过 XML 属性提供了多种主题定制选项,您可以使用这些选项完全改变此视图的外观和感觉,以匹配您应用的主题。
app:pinLength="6" // Change the pin length
app:keypadTextColor="#E6E6E6" // Change the color of the keypad text
app:keypadTextSize="16dp" // Change the text size in the keypad
app:keypadButtonSize="72dp" // Change the size of individual keys/buttons
app:keypadVerticalSpacing="24dp" // Alters the vertical spacing between the keypad buttons
app:keypadHorizontalSpacing="36dp" // Alters the horizontal spacing between the keypad buttons
app:keypadButtonBackgroundDrawable="@drawable/bg" // Set a custom background drawable for the buttons
app:keypadDeleteButtonDrawable="@drawable/ic_back" // Set a custom drawable for the delete button
app:keypadDeleteButtonSize="16dp" // Change the size of the delete button icon in the keypad
app:keypadShowDeleteButton="false" // Should show the delete button, default is true
app:keypadDeleteButtonPressedColor="#C8C8C8" // Change the pressed/focused state color of the delete button
app:dotEmptyBackground="@drawable/empty" // Customize the empty state of the dots
app:dotFilledBackground"@drawable/filled" // Customize the filled state of the dots
app:dotDiameter="12dp" // Change the diameter of the dots
app:dotSpacing="16dp" // Change the spacing between individual dots
app:indicatorType="fillWithAnimation" // Choose between "fixed", "fill" and "fillWithAnimation"
贡献指南
这个库内容全面,提供了大量的自定义选项。如果您发现了任何错误或希望对它进行改进,欢迎通过提交 PR(拉取请求)来贡献力量。
关于作者
Aritra Roy
Android 与后端开发者,博客作者,设计师,健身爱好者。
谷歌应用商店
个人博客
Stack Overflow
Twitter
LinkedIn ![]()
许可协议
Copyright 2017 aritraroy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
当然,我会尽力按照您的要求进行翻译。不过,您似乎忘记提供要翻译的文本。请您提供原文,我才能帮助您进行翻译。