今天分享一个手写签名特别好用的框架
第一步,添加依赖
implementation 'com.github.gcacace:signature-pad:1.3.1'
第二步,添加布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white">
<com.github.gcacace.signaturepad.views.SignaturePad
android:id="@+id/pad"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/edt_shape"
android:layout_margin="20dp"/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal">
<Button
android:id="@+id/bt_clear"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="清除"
android:textColor="@color/white"
android:background="@color/xian"
android:textSize="16sp"/>
<Button
android:id="@+id/bt_save"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_height="match_parent"
android:text="保存"
android:textColor="@color/white"
android:background="@color/blue"
android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>
第三步,使用
bt_save.setOnClickListener {
if (pad.isEmpty) {
ToastUtils.showShort("请签名")
return@setOnClickListener
}
pad.signatureBitmap//即为签名图片
}
bt_clear.setOnClickListener {
pad.clear()
}