java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE in Button background failure

孤者浪人 提交于 2019-11-26 07:43:35

问题


android Button background failure

when I try to add

android:background=\"@drawable/roundedbutton\"

into the .xml

<Button
     android:id=\"@+id/button_stop\"
     style=\"@android:style/Widget.Button\"
     android:layout_width=\"match_parent\"
     android:layout_height=\"wrap_content\"
     android:layout_margin=\"3dp\"
     android:background=\"@drawable/roundedbutton\"
     android:layout_weight=\"1\"
     android:text=\"stop\"
     android:textSize=\"18sp\" />

the roundedbutton.xml

<?xml version=\"1.0\" encoding=\"utf-8\"?>
<shape xmlns:android=\"http://schemas.android.com/apk/res/android\"
    android:shape=\"rectangle\">
    <solid android:color=\"@color/colorPrimary\" />
    <corners android:bottomRightRadius=\"8dp\"
        android:bottomLeftRadius=\"8dp\"
        android:topRightRadius=\"8dp\"
        android:topLeftRadius=\"8dp\"/>
</shape>

the button became blank and Android Studio 3.2.1 gives an error

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.view.ViewGroup_Delegate.drawShadow(ViewGroup_Delegate.java:86)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:58)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20075)
    at android.view.View_Delegate.draw(View_Delegate.java:68)
    at android.view.View.draw(View.java:19849)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4333)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20075)
    at android.view.View_Delegate.draw(View_Delegate.java:68)
    at android.view.View.draw(View.java:19849)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4333)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20075)
    at android.view.View_Delegate.draw(View_Delegate.java:68)
    at android.view.View.draw(View.java:19849)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4333)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20210)
    at android.view.View_Delegate.draw(View_Delegate.java:56)
    at android.view.View.draw(View.java:20177)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:405)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:552)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:426)
    at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
    at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:671)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Thank you.


回答1:


UPDATE

The fix for this will be included in Android Studio 3.5 Canary 2

java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE

The issue with targetSdkVersion 28

Looks like this started being enforced in P: https://developer.android.com/reference/android/graphics/Canvas#clipRect(android.graphics.RectF,%20android.graphics.Region.Op)

also reported here

  • https://issuetracker.google.com/issues/121235731
  • https://github.com/facebook/stetho/issues/607
  • https://github.com/ArthurHub/Android-Image-Cropper/issues/553
  • https://github.com/ArthurHub/Android-Image-Cropper/pull/588

Temporary solution for your case

Use

<corners
    android:radius="8dp"/>

instead of

<corners android:bottomRightRadius="8dp"
    android:bottomLeftRadius="8dp"
    android:topRightRadius="8dp"
    android:topLeftRadius="8dp"/>



回答2:


Same issue occur in my end, it was fixed now Change the targetSdkVersion 28 to 27 in build.gradle. Thanks




回答3:


This is what fixed it for me:

.setCropShape(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? CropImageView.CropShape.RECTANGLE : CropImageView.CropShape.OVAL)



回答4:


For those of you who still haven't figured out how to solve this, just Try to read the error and understand where it stems from.

Read all the call stack, don't be afraid, line by line, and find the library which use the function clipRect().

Its probably an old library which you need to updated (in my scenario, it was Lottie, which didn't report in the build.gradle that I haven't had the most recent library).




回答5:


Try this

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp" android:color="@color/black"   />
    <solid android:color="@color/black" />
    <corners android:radius="7dp" />

</shape>



回答6:


try removing " style="@android:style/Widget.Button"".

 <Button
            android:id="@+id/button_stop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:background="@drawable/roundedbutton"
            android:layout_weight="1"
            android:text="stop"
            android:textSize="18sp" />



回答7:


For me it got fixed up when I changed

<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>

to

<corners
android:radius="8dp"/>

in my buttondesign.xml file and replaced

<Button
        android:id="@+id/btn_verify"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/yellow_btn_bg"
        android:text="Verify"
        android:textSize="16sp"
        android:layout_margin="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:textColor="@color/white"
        />

with

<Button
        android:id="@+id/btn_verify"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/yellow_btn_bg"
        android:text="Verify"
        android:textSize="16sp"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:textColor="@color/white"
        />



回答8:


if you encounter this problem in an activity while you do not detect the report with the solutions proposed here, it is that you use an instatble library which generates this error .. try to change the version of this library, and your problem will be solved



来源:https://stackoverflow.com/questions/52922866/java-lang-illegalargumentexception-invalid-region-op-only-intersect-and-diffe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!