虽然在Android 8.1.0版上运行可以,但是在Android 6.0.1版中会引发此异常。
我的代码是
<Button
android:id="@+id/signin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:layout_marginTop="@dimen/button_top_margin"
android:layout_marginRight="14dp"
android:background="@drawable/button_background_orange"
android:text="@string/action_sign_in"
android:textColor="@color/colorText" />
button_background_orange.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F29439" />
<corners android:radius="25dp" />
<stroke
android:width="1dp"
android:color="#F29439" />
</shape>
例外:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dinesh.kumarijobemployer, PID: 22475
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dinesh.kumarijobemployer/com.dinesh.kumarijobemployer.LoginActivity}: android.view.InflateException: Binary XML file line #132: Binary XML file line #132: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7223)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #132: Binary XML file line #132: Error inflating class Button
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)