web-dev-qa-db-fra.com

java.lang.IllegalArgumentException: Region.Op non valide - uniquement INTERSECT et DIFFERENCE dans l'échec d'arrière-plan du bouton

Erreur de fond du bouton Android

quand j'essaye d'ajouter

Android:background="@drawable/roundedbutton"

dans le .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" />

le 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>

le bouton est devenu vide et Android Studio 3.2.1 génère une erreur

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)

Je vous remercie.

6
Mike Lin

METTRE &AGRAVE; JOUR

Le correctif pour cela sera inclus dans Android Studio 3.5 Canary 2

 enter image description here

Java.lang.IllegalArgumentException: Region.Op non valide - uniquement INTERSECT et DIFFERENCE 

Le problème avec targetSdkVersion 28 

On dirait que cela a commencé d'être appliqué dans P: https://developer.Android.com/reference/Android/graphics/Canvas#clipRect(Android.graphics.RectF,%20Android.graphics.Region.Op)

également rapporté ici

Solution temporaire pour votre cas

Utilisation 

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

au lieu de 

<corners Android:bottomRightRadius="8dp"
    Android:bottomLeftRadius="8dp"
    Android:topRightRadius="8dp"
    Android:topLeftRadius="8dp"/>
11
Nilesh Rathod

Le même problème se produit chez moi, il a été corrigé maintenant Changez le targetSdkVersion 28 to 27 dans build.gradle . Merci

1
Praveen Kumar Verma

Essaye ça

    <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>
0
pratik vekariya

essayez de supprimer "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" />
0
Abdul