Zahid-Ali-Shah SignatureView 不再工作了?

Zahid-Ali-Shah SignatureView Not Working anymore?

我已经使用 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'

Updated Signature Pad