1
我想更改我的進度欄的漸變顏色。現在,我可以將其更改爲純色,但我無法將其更改爲漸變色。Android更改形狀可繪製顏色
LayerDrawable progressDrawable = (LayerDrawable) myProgressBar.getProgressDrawable();
// get the color drawable of the progress bar
Drawable primaryColor = progressDrawable.getDrawable(1);
// set the new color.
primaryColor.setColorFilter(ContextCompat.getColor(getContext(), R.color.yellow), PorterDuff.Mode.SRC_OVER);
取而代之的是純色我想改變漸變色。
編輯我可繪製文件
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="@color/gray300"
android:centerColor="@color/gray400"
android:centerY="0.75"
android:endColor="@color/gray500"
android:angle="270"
/>
</shape>
</item>
<item
android:id="@+id/progress">
<clip>
<shape>
<corners
android:radius="5dip" />
**I want to change this gradient color**
<gradient
android:startColor="#33FF33"
android:endColor="#008000"
android:angle="270" />
</shape>
</clip>
</item>
</layer-list>
我得到的錯誤'android.graphics.drawable.LayerDrawable不能轉換爲android.graphics.drawable.GradientDrawable'。我已經包含可繪製文件。 –
編輯我的答案 – ZeroOne