1

当我尝试使用自定义键盘在 Android P Beta 上出现异常时,一切正常,直到 Android Oreo 但最近发生了崩溃。只需尝试找出哪个类可能导致异常。目前无法访问完整的自定义键盘代码,因此不发布代码。

java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed
    at android.graphics.Canvas.checkValidClipOp(Canvas.java:779)
    at android.graphics.Canvas.clipRect(Canvas.java:826)
    at android.inputmethodservice.KeyboardView.onBufferDraw(KeyboardView.java:666)
    at android.inputmethodservice.KeyboardView.onDraw(KeyboardView.java:647)
    at android.view.View.draw(View.java:20205)
    at android.view.View.updateDisplayListIfDirty(View.java:19080)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw(View.java:20208)
    at android.view.View.updateDisplayListIfDirty(View.java:19080)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw(View.java:20208)
    at com.android.internal.policy.DecorView.draw(DecorView.java:784)
    at android.view.View.updateDisplayListIfDirty(View.java:19080)
    at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:685)
    at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:691)
    at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:799)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:3259)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3075)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2455)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1443)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7125)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:935)
    at android.view.Choreographer.doCallbacks(Choreographer.java:747)
    at android.view.Choreographer.doFrame(Choreographer.java:682)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:921)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6649)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
4

2 回答 2

3

它实际上告诉你原因:

只允许 INTERSECT 和 DIFFERENCE

原因写在这里

此方法在 API 级别 26 中已弃用。除 INTERSECT 和 DIFFERENCE 之外的 Region.Op 值具有扩展剪辑的能力。画布剪辑 API 仅用于扩展剪辑作为恢复操作的结果。这使视图父级可以剪切画布以明确定义其子级的最大绘图区域。推荐的替代调用是 clipRect(RectF) 和 clipOutRect(RectF);从 API 级别 API 级别 Build.VERSION_CODES.P 开始,只有 INTERSECT 和 DIFFERENCE 是有效的 Region.Op 参数。

所以你要么必须使用较低的 targetSdk 版本(你不应该这样做,因为谷歌会在年底之前强制你使用至少 26 个),或者你通过画布以不同的方式使用你的剪辑来修复它.

我在这里问了一个关于它的问题,有什么替代方法。

于 2018-05-21T13:32:51.337 回答
0

你只需要删除这一行:

.setCropShape(CropImageView.CropShape.OVAL)
于 2019-01-09T10:45:27.337 回答