自定义键盘无法在Android P Beta上运行

时间:2018-05-16 12:44:42

标签: android android-softkeyboard android-9.0-pie android-custom-keyboard

当我尝试使用自定义键盘在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)

2 个答案:

答案 0 :(得分:3)

它实际上告诉你原因:

  

只允许INTERSECT和DIFFERENCE

原因是here

  

此方法在API级别26中已弃用.Region.Op值为other   比INTERSECT和DIFFERENCE能够扩展剪辑。该   画布剪辑API仅用于展开剪辑   恢复操作。这使视图父级可以将画布剪切到   明确定义其子项的最大绘图区域。该   推荐的替代调用是clipRect(RectF)和   clipOutRect(RectF);自API Level API级别Build.VERSION_CODES.P起   只有INTERSECT和DIFFERENCE是有效的Region.Op参数。

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

我已经问了一个关于它的问题here,以及替代方案。

答案 1 :(得分:0)

您只需要删除此行:

.setCropShape(CropImageView.CropShape.OVAL)