Tôi đã xem tài liệu cho GradientColor https://developer.android.com/reference/android/R.styleable.html#GradientColor. Làm thế nào tôi có thể xác định một màu gradient trong XML và áp dụng nó vào một vector XML drawable?GradientColor có thể được sử dụng để xác định một gradient cho một điền hoặc đột quỵ hoàn toàn trong XML?
Tôi đã thử trong color.xml, styles.xml và trong một vector XML có thể vẽ được.
tôi nhận được báo lỗi "Không thể chuyển đổi @ id/gradclor thành một ColorStateList" với:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="120dp"
android:height="120dp"
android:viewportWidth="120.0"
android:viewportHeight="120.0">
<path
android:name="play_triangle"
android:pathData="M 30 30 L 30 90 L 80 60 z"
android:strokeColor="@id/gradclor"
android:strokeWidth="5"/>
<color
android:name="@+id/gradclor"
android:startColor="#FFFFFF"
android:endColor="#00FFFF"
android:angle="145"/>
</vector>
hoặc "Không thể chuyển đổi #FFFFFFFF # 00FFFFFF 145 thành ColorStateList" khi sử dụng:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="120dp"
android:height="120dp"
android:viewportWidth="120.0"
android:viewportHeight="120.0">
<path
android:name="play_triangle"
android:pathData="M 30 30 L 30 90 L 80 60 z"
android:strokeColor="@color/GradientStrokeBorder"
android:strokeWidth="5"/>
</vector>
những điều sau đây color.xml:
<color name="GradientStrokeBorder">
<item name="android:startColor">#FFFFFF</item>
<item name="android:endColor">#00FFFF</item>
<item name="android:angle">145</item>
</color>
Công việc tuyệt vời. Điều đáng nói là điều này làm hỏng ứng dụng trên các thiết bị thấp hơn API 24 (7.0) vì vậy tôi đặt một phiên bản đề cập đến độ dốc trong * res/color/blue_gradient.xml * ('@ color/blue_gradient') trong ** res/drawable-v24 ** và phiên bản đề cập đến màu thường xuyên trong ** res/drawable **. – TTransmit