Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从内部引用主题的属性<;包含标签_Android_Android Layout_Android Support Library - Fatal编程技术网

Android 从内部引用主题的属性<;包含标签

Android 从内部引用主题的属性<;包含标签,android,android-layout,android-support-library,Android,Android Layout,Android Support Library,在我更新了targetSdkVersion并将我的应用程序的libs版本支持到Oreo后,我遇到了一个问题(27)。问题是,当我在Android 4、API 19上运行我的应用程序时,我得到了运行时错误。问题是它找不到被引用属性的值。代码如下: styles.xml: <style name="CustomStyle" parent="OtherCustomStyle"> <item name="screenPrimaryColor">@color/primary

在我更新了
targetSdkVersion
并将我的应用程序的libs版本支持到Oreo后,我遇到了一个问题(27)。问题是,当我在Android 4、API 19上运行我的应用程序时,我得到了运行时错误。问题是它找不到被引用属性的值。代码如下:

styles.xml:

<style name="CustomStyle" parent="OtherCustomStyle">
    <item name="screenPrimaryColor">@color/primary</item>
    <item name="screenPrimaryColorDark">@color/primaryDark</item>
</style>

<attr name="screenPrimaryColor" format="reference" />
<attr name="screenPrimaryColorDark" format="reference" />

@颜色/原色
@颜色/原色暗
activity_test.xml:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/CustomStyle">

    <include layout="@layout/inner_test"/>
</FrameLayout>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/instant_sale_bottom_margin">

    <!-- HEADER -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="?attr/screenPrimaryColor"
        android:baselineAligned="false">

        <!-- REST OF MY LAYOUT -->

    </LinearLayout>
</LinearLayout>

internal_test.xml:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/CustomStyle">

    <include layout="@layout/inner_test"/>
</FrameLayout>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/instant_sale_bottom_margin">

    <!-- HEADER -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="?attr/screenPrimaryColor"
        android:baselineAligned="false">

        <!-- REST OF MY LAYOUT -->

    </LinearLayout>
</LinearLayout>

如您所见,样式作为主题应用于
活动\u test.xml
。然而,这种组合(支持lib27和Android 4.4)不起作用,应用程序在膨胀布局时崩溃。由于包含的视图中的android:background=“?attr/screenPrimaryColor”而崩溃。在我更新支持库之前,它运行良好。此外,这也适用于运行Android更新版本4的设备上的新支持库

我认为这可能是支持库中的一个bug。我的问题是你们中是否有人也遇到过这个问题

(顺便说一句,我找到了“解决方案”,即在包含的视图中设置相同的主题(
internal_test.xml
),但是,这是一个肮脏的解决方案,因为
internal_test.xml
可以在应用程序的不同部分重用。)