自定义键盘不工作在Android P Beta版(Custom Keyboard not worki

2019-09-29 04:51发布

当我尝试使用自定义键盘了Android上的P贝塔异常,一切正常,直到Android的奥利奥,但最近有一个崩溃。 只是试图找出哪些类可能是负责例外。 目前无法访问完整的自定义键盘代码,因此不张贴代码。

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)

Answer 1:

它实际上是告诉你的原因:

只有交叉,差异是允许

究其原因是写在这里

这种方法是在API级别弃用比相交并DIFFERENCE其他26. Region.Op值具有扩大夹的能力。 裁剪的API画布旨在不仅扩大了剪辑作为恢复操作的结果。 这使视图父剪辑画布,明确界定其子女的最大绘图区域。 推荐的备选调用是clipRect(RectF)和clipOutRect(RectF); 由于API级别API级别的Build.VERSION_CODES.P仅相交,并差是有效的Region.Op参数。

所以,你要么必须使用较低targetSdk版本(你不应该,因为谷歌将迫使你在今年年底至少要用26的话),或者您通过画布以不同的方式使用您的剪辑修复。

我问过一个问题,关于它在这里 ,一个什么样的替代。



Answer 2:

你只需要删除此行:

.setCropShape(CropImageView.CropShape.OVAL)


文章来源: Custom Keyboard not working on Android P Beta