标签:
先安利,收纳库:https://github.com/ddwhan0123/Useful-Open-Source-Android 每天都在更!!!
上一篇关于学习和职场的一些看法,评论不错阅读量不佳(估计是没分享到主页的缘故吧,这里再安利下):http://blog.csdn.net/ddwhan0123/article/details/51646255
废话不多说,开始这一篇的内容
之前也有看到过一些类似的应用锁实现,今天看到个比较好看+好用的就推荐给大家
先看下运行效果:
How to use?
Gradle
dependencies {
// other dependencies here
compile ‘com.andrognito.pinlockview:pinlockview:1.0.0‘
}
Maven
<dependency>
<groupId>com.andrognito.pinlockview</groupId>
<artifactId>pinlockview</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
Eclipse的小伙们再见!!!
来看下例子里怎么用的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/mine_shaft"
tools:context="com.andrognito.pinlockviewapp.SampleActivity">
<ImageView
android:id="@+id/profile_image"
android:layout_width="84dp"
android:layout_height="84dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp"
android:src="@drawable/img_no_avatar" />
<TextView
android:id="@+id/profile_name"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:fontFamily="sans-serif-thin"
android:gravity="center"
android:maxLines="1"
android:text="Welcome"
android:textColor="@color/white"
android:textSize="34sp" />
<com.andrognito.pinlockview.IndicatorDots
android:id="@+id/indicator_dots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/profile_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp" />
<com.andrognito.pinlockview.PinLockView
android:id="@+id/pin_lock_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/indicator_dots"
app:keypadButtonSize="72dp"
app:keypadTextSize="18dp"
app:keypadShowDeleteButton="false"
app:keypadTextColor="@color/white"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp" />
</RelativeLayout>
主要是密码锁的 IndicatorDots 和 “按键实现的” PinLockView 就和普通控件一样用就行,最多加点自定义标签,标签在后面会解释
看下Activity里怎么用的(解释在注视里)
public class SampleActivity extends AppCompatActivity {
public static final String TAG = "PinLockView";
private PinLockView mPinLockView;
private IndicatorDots mIndicatorDots;
//监听密码输入情况
private PinLockListener mPinLockListener = new PinLockListener() {
//输入长度达到length后触发
@Override
public void onComplete(String pin) {
Log.d(TAG, "Pin complete: " + pin);
Toast.makeText(SampleActivity.this, "密码输完了是 " + pin, Toast.LENGTH_SHORT).show();
}
//为空时触发
@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);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sample);
mPinLockView = (PinLockView) findViewById(R.id.pin_lock_view);
mIndicatorDots = (IndicatorDots) findViewById(R.id.indicator_dots);
//2个控件产生关联
mPinLockView.attachIndicatorDots(mIndicatorDots);
//添加监听事件
mPinLockView.setPinLockListener(mPinLockListener);
//设置密码总长度
mPinLockView.setPinLength(4);
//设置按钮颜色 mPinLockView.setTextColor(getResources().getColor(R.color.white));
}
}
列出其他的一些自定义标签
app:pinLength="6" // 改pin的长度
app:keypadTextColor="#E6E6E6" // 设置键盘字体颜色
app:keypadTextSize="16dp" // 设置键盘字体大小
app:keypadButtonSize="72dp" // 设置按钮大小
app:keypadVerticalSpacing="24dp" // 改变键盘按钮之间的垂直间隔
app:keypadHorizontalSpacing="36dp" // 改变键盘按钮之间的水平间距
app:keypadButtonBackgroundDrawable="@drawable/bg" // 设置按钮背景图片
app:keypadDeleteButtonDrawable="@drawable/ic_back" // 设置删除按钮图片
app:keypadDeleteButtonSize="16dp" // 设置删除按钮图标大小
app:keypadShowDeleteButton="false" // 设置是否显示删除按钮,默认不显示
app:keypadDeleteButtonPressedColor="#C8C8C8" // 更改删除按钮的按/焦点状态颜色
app:dotEmptyBackground="@drawable/empty" // 自定义点的空状态
app:dotFilledBackground"@drawable/filled" // 自定义点的填充状态
app:dotDiameter="12dp" // 改变点的直径
app:dotSpacing="16dp" // 改变单个点之间的间距
源码地址:https://github.com/aritraroy/PinLockView/archive/master.zip
该库已收入
翻翻git之---逻辑清晰,简单好用的App内部锁控件 PinLockView
标签:
原文地址:http://blog.csdn.net/ddwhan0123/article/details/51668783