起因:实现第二个样式时
报错如下:
FATAL EXCEPTION: main
Process: com.company.exam03, PID: 11577
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.exam03/com.company.exam03.MainActivity}: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class Button
出错位置:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/test1" android:text="测试" />
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:bottomLeftRadius="8dp"/> <corners android:bottomRightRadius="8dp"/> <corners android:topLeftRadius="8dp"/> <corners android:topRightRadius="8dp"/> <corners android:radius="8dp"/> <gradient android:startColor="#092fda" android:endColor="#ffffff" android:type="radial" /> </shape>
原因:
API中查询得知
android:gradientRadius
android:type="radial"
.配置gradient type="radial"时 必须配置gradientRadius属性。