[英]Android App crashes on launch | IntelliJ Android Studio
[英]Android Studio app crashes on launch when using ?colorVariant in xml drawable
我的 xml drawables 中有一个形状,它使用了我的主题的 styles 文件。xml 文件:
<shape android:shape="oval">
<gradient
android:gradientRadius="134dp"
android:startColor="?colorPrimary"
android:centerColor="#000000"
android:endColor="#000111"
android:type="radial" />
</shape>
如您所见, startColor 使用 colorPrimary 属性。 但是,当我在 Android Studio 模拟器中启动应用程序时,它会崩溃而没有构建错误。 当我用随机的十六进制颜色替换?colorPrimary 时,一切似乎都很好。 我正在使用 API 24,据我所知你可以使用?colorVariant for >API 21。不知道我在这里做错了什么。
use something like this android:startColor="@color/purple_500"
see your colors.xml and call your colors from there
或者
If you want to use 2 colors for day and night go into your project directory resources folder(res)
and create new folder name drawable-night
and copy your shape.xml
from drawable
and paste it in drawable-night
go to android studio now you有 2 个shape.xml
文件一个是晚上,另一个是白天添加 colors 喜欢你想添加喜欢
shape.xml 添加android:startColor="@color/purple_500"
并为 shape.xml(night) 添加android:startColor="@color/purple_200"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.