在 LinearLayout 上添加可绘制背景时,应用程序在 API 16 Phone 崩溃

App crash on API 16 Phone when add drawable background on LinearLayout

在LinearLayout中添加drawable frame background时,APP会在API 16 19(已测试)崩溃,但在API 21 27可以正常工作。LineayLayout是recyclerView中的item view,有此背景没有动画,它应该适用于所有 API 级别

        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorGreen</item>
    <item name="colorPrimaryDark">@color/colorGreen</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_small"
android:background="@drawable/bg_frame_rounded_transparent_strokegreens"
android:orientation="vertical">

bg_frame_rounded_transparent_strokegreens:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:shape="rectangle">
            <stroke
                android:width="1dp"
                android:color="?attr/colorPrimary">
            </stroke>

        <corners
            android:topLeftRadius="@dimen/item_change_txv_corner_radius"
            android:topRightRadius="@dimen/item_change_txv_corner_radius"
            android:bottomRightRadius="@dimen/item_change_txv_corner_radius"
            android:bottomLeftRadius="@dimen/item_change_txv_corner_radius"/>
    </shape>
</item>

错误:

07-30 16:51:26.794 4526-4526/io.ionic.parkstash_parking_app E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at io.ionic.parkstash_parking_app.view.addparking.SelfParkingListAdapter.onCreateViewHolder(SelfParkingListAdapter.java:53)
    at io.ionic.parkstash_parking_app.view.addparking.SelfParkingListAdapter.onCreateViewHolder(SelfParkingListAdapter.java:27)
    at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6685)
    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5869)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
    at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
    at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
    at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
    at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3225)
    at android.view.View.measure(View.java:15172)
    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:602)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:415)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:811)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
    at android.view.Choreographer$C

您已使用 ?attr/colorPrimary 作为您的颜色,但这仅在您使用 AppCompat 主题时适用于较旧的 API。检查您的主题是否有来自 AppCompat 的父主题。