Нарисованный градиент выглядит хорошо при предварительном просмотре, но в реальном приложении он уничтожен - PullRequest
1 голос
/ 14 октября 2019

Итак, я хочу дать своему макету ограничения градиент, который начинается с colorSecondary и заканчивается colorPrimary. Это мой activity_home.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient_home"
    tools:context=".HomeActivity">

</androidx.constraintlayout.widget.ConstraintLayout>

drawable / градиент_home.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:type="linear"
        android:angle="180"
        android:startColor="@color/colorSecondary"
        android:endColor="@color/colorPrimary" />
</shape>

Это предварительный просмотр: https://imgur.com/a/xx5smf4 Это актуальное приложение: https://imgur.com/a/FOwygyB Почему не совпадает? Что я могу сделать? Другие файлы: attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="colorPrimaryLight" format="color"/>
    <attr name="colorSecondary" format="color"/>
    <attr name="colorSecondaryLight" format="color"/>
    <attr name="colorSecondaryDark" format="color"/>
</resources>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#202020</color>
    <color name="colorPrimaryDark">#000000</color>
    <color name="colorPrimaryLight">#474747</color>
    <color name="colorSecondary">#121212</color>
    <color name="colorSecondaryLight">#383838</color>
    <color name="colorSecondaryDark">#000000</color>
    <color name="colorAccent">#ffffff</color>
</resources>

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="BaseAppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorPrimaryLight">@color/colorPrimaryLight</item>
        <item name="colorSecondary">@color/colorSecondary</item>
        <item name="colorSecondaryLight">@color/colorSecondaryLight</item>
        <item name="colorSecondaryDark">@color/colorSecondaryDark</item>

    </style>


</resources>
...