您可以創建自定義XML,然後setbackgrounddrawable你的進度編程,
myProgressBar.setProgressDrawable(R.drawable.progress_horizontal)的;
* progress_horizontal.xml *
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ffffd300"
android:centerColor="#ffffb600"
android:centerY="0.75"
android:endColor="#ffffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
正如我在我的問題已經提到這個解決方案犯規解決我的問題。我需要隨時根據用戶輸入更改搜索欄的進度。 XML drawable只能設置一個靜態drawable。即使我使用代碼中的自定義drawable,它只會改變seekbar的背景而不是進度 –