[英]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.