android button后台失败
当我尝试添加时
android:background="@drawable/roundedbutton"
放入.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" />
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>
按钮变为空白,Android Studio 3.2.1出现错误
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)
谢谢。
答案 0 :(得分:17)
更新
java.lang.IllegalArgumentException:无效的Region.Op-仅是INTERSECT和DIFFERENCE
targetSdkVersion 28
看起来像这样开始在P中执行:https://developer.android.com/reference/android/graphics/Canvas#clipRect(android.graphics.RectF,%20android.graphics.Region.Op)
也在这里报道了
针对您情况的临时解决方案
使用
<corners
android:radius="8dp"/>
代替
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>
答案 1 :(得分:3)
同一问题最终发生,现在已解决
在 build.gradle 中更改targetSdkVersion 28 to 27
。谢谢
答案 2 :(得分:2)
这是为我解决的问题:
.setCropShape(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? CropImageView.CropShape.RECTANGLE : CropImageView.CropShape.OVAL)
答案 3 :(得分:0)
尝试一下
<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>
答案 4 :(得分:0)
尝试删除“ 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" />
答案 5 :(得分:0)
对我来说,当我改变时它已经固定了
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>
到
<corners
android:radius="8dp"/>
在我的buttondesign.xml文件中并替换
<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"
/>
使用
<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"
/>
答案 6 :(得分:0)
如果您在活动中遇到此问题而未使用此处建议的解决方案检测到报告,则说明您使用的是生成此错误的不确定库..尝试更改该库的版本以及您的问题将解决
答案 7 :(得分:0)
对于仍然还不知道如何解决此问题的人,只需尝试阅读错误并了解错误的根源。
逐行阅读所有调用堆栈,不要害怕,并找到使用函数clipRect()
的库。
可能是您需要更新的旧库(在我的情况下是Lottie,在build.gradle中没有报告我没有最新的库)。
答案 8 :(得分:0)
在我的情况下,该库发生了错误,我在该库对应的github问题中找到了解决方法