2017-07-10 8 views
1

私はSeekBarを使用していますが、別の色を使用する必要がありますSeekBarの進捗状況。drawable xml形の色が真似る

だから私は、これはdrawaleのxmlですプログラムで

描画可能形状の色を変更する必要があります。 seekbar_points.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item 
    android:id="@android:id/background" 
    android:drawable="@drawable/points_bg" /> 
<item android:id="@android:id/progress"> 
    <clip android:drawable="@drawable/points_progress" /> 
</item> 
</layer-list> 

points_progress.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="line"> 
<stroke android:width="6dp" android:color="@color/colorAccent" /> 
</shape> 

points_bg.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="line"> 
<stroke android:width="6dp" android:color="@color/color7" /> 
</shape> 

enter image description here

私は動的にこの緑の色領域を変更する必要があります。

seekBar.getProgressDrawable().setColorFilter(ContextCompat.getColor(сontext, R.color.color_new), PorterDuff.Mode.SRC_IN); 

更新:
場合は、このために私は

答えて

0

はこれを使用して....アイデアを事前に 感謝を提案してください。このXML

におけるカラーpoints_progress.xmlを設定していますあなたは進歩したエリアのみの色を変更したい:

LayerDrawable progressDrawable = (LayerDrawable) seekBar.getProgressDrawable(); 
Drawable filledDrawable = progressDrawable.findDrawableByLayerId(android.R.id.progress); 
filledDrawable.setColorFilter(ContextCompat.getColor(сontext, R.color.color_new), PorterDuff.Mode.SRC_IN); 
+0

私はクラスキャストを持っていますここの例外 – CarinaMj

+0

seekbar.getProgressDrawable()は 'X extends Drawable'を返します。返された特定のクラスを投稿することはできますか? – DeKaNszn

+0

@CarinaMjあなたの状況に合わせてシンプルなコードに変更しました – DeKaNszn

関連する問題