问题描述
我已经使用 zahid-ali-shah/SignatureView 的 SignatureView 几年了,今天在一个新项目中实施它我无法绘制签名,并且已经在模拟器和物理设备上对其进行了测试。
这在加快将用户签名捕获为位图的过程方面很方便,希望这只是一个简单的修复。也很好奇是否有其他人遇到同样的问题。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:title="@string/SIGNATURE_TOOLBAR_TITLE" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/signature_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.kyanogen.signatureview.SignatureView
xmlns:sign="http://schemas.android.com/apk/res-auto"
android:id="@+id/signature_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
sign:penSize="5dp"
sign:backgroundColor="#ffffff"
sign:penColor="#000000"
sign:enableSignature="false"/>
<Button
android:id="@+id/submit"
style="@style/ButtonStyle"
android:layout_width="161dp"
android:layout_height="47dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Submit Signature"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@+id/clear"
style="@style/ButtonStyle"
android:layout_width="142dp"
android:layout_height="43dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:text="Clear"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
签名视图是一个片段“SignatureFragment”我在视图上使用绑定,“signature_view”可以使用 _binding
OnViewCreated:
override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
super.onViewCreated(view,savedInstanceState)
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
//Load UI Listeners
attachListeners()
}
attachListeners():
private fun attachListeners() {
//Signature Pad Setup
_binding?.signatureView?.penColor = Color.BLACK
//Load all of the listeners here for organization
_binding?.submit?.setonClickListener(){
val signatureSubmitaction =
SignatureFragmentDirections.actionSignatureFragmentToratingFragment()
findNavController().navigate(signatureSubmitaction)
}
_binding?.clear?.setonClickListener {
confirmClearOfSignatureView()
}
}
confirmClearSignature():
private fun confirmClearOfSignatureView() {
//Create Alert Builder and Control Clear
val clearSignatureDialog = AlertDialog.Builder(context)
clearSignatureDialog.setTitle("Clear Signature?")
clearSignatureDialog.setMessage("Are you sure you want to clear your current signature? This operation is final.")
clearSignatureDialog.setPositiveButton("Yes,Clear") { dialog,which ->
_binding?.signatureView?.clearCanvas()
}
clearSignatureDialog.setNegativeButton("Don't Clear") { dialog,which ->
//Default Action is dismiss
}
clearSignatureDialog.show()
}
从我在文档中看到的和我过去的经验来看,我应该至少能够看到屏幕上的笔画。我什么也看不见。
对可能发生的情况或如何解决此问题有任何建议吗?如果可能的话,我很想继续使用这个 Repo。
解决方法
我无法使用上述库解决此问题,并切换到支持更好的库:
implementation 'com.github.gcacace:signature-pad:1.3.1'