android - 可绘制渐变在预览中看起来不错,但在实际应用中被破坏了
问题描述
所以,我想给我的约束布局一个以 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>
可绘制/gradient_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>
颜色.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>
样式.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>
解决方案
推荐阅读
- postgresql - 当我在 db(此处为 postgres)中的结构未知时,如何检索 GoLang 数据库/sql 中的值?
- html - 无法在登陆网页上打开下拉菜单、超链接和超链接按钮
- php - 期待 'STRING'、'NUMBER'、'NULL'、'TRUE'、'FALSE'、'{'、'[',得到 'undefined' (PHP)
- mysql - 使用别名到where子句查询mysql
- python - 处理日期时熊猫效率的问题
- three.js - 如何在使用 THREE.js 的客户片段着色器中将 RGB 用于 tDiffuse
- docker - Docker:./entrypoint.sh 未找到
- syntax - 在 Java 中打印一个模式
- c - 使用 const 指针或 const 数据有什么好处?
- php - 在laravel中将多个数据插入数据库