i want to change the color of progressbar as the cursor is moved, but setProgressDrawable() seems to work only within OnCreate() method, if i change the ProgressDrawable inside onProgressChanged method inspecting mSeekBar i can see that the value of Currentdrawable and ProgressDrawable is updated but the progressbar disappear and it reappears only when the progressdrawable changes back to the old value (the one set in the onCreate method)
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromTouch) { seekBar.setProgressDrawable(new_drawable); } Full code: public class SeekBar2 extends Activity implements SeekBar.OnSeekBarChangeListener { SeekBar mSeekBar; TextView mProgressText; TextView mTrackingText; static LayerDrawable mdrawable_green; static LayerDrawable mdrawable_blue; static LayerDrawable mdrawable_red; enum BarColor { RED, BLUE, GREEN; LayerDrawable getDrawable(){ switch(this){ case RED: return mdrawable_red; case BLUE: return mdrawable_blue; case GREEN: return mdrawable_green; default : return mdrawable_red; } } }; BarColor mcolor; public BarColor getColor() { return mcolor; } public void setColor(SeekBar seekbar,BarColor color) { this.mcolor = color; seekbar.setProgressDrawable(color.getDrawable()); } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mSeekBar = (SeekBar) findViewById(R.id.seek); mdrawable_green = (LayerDrawable) this.getResources().getDrawable (R.drawable.pgreen); mdrawable_blue = (LayerDrawable)this.getResources().getDrawable (R.drawable.pblue); mdrawable_red = (LayerDrawable)this.getResources().getDrawable (R.drawable.pred); setColor(mSeekBar ,BarColor.RED); mSeekBar.setOnSeekBarChangeListener(this); mProgressText = (TextView) findViewById(R.id.progress); mTrackingText = (TextView) findViewById(R.id.tracking); } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { mProgressText.setText(progress + " " + "seekbar_from_touch" + "=" + fromTouch); BarColor color; if(progress < 33) color = BarColor.RED; else if ((progress>=33) && (progress<66)) color = BarColor.BLUE; else color = BarColor.GREEN; if(color!=mcolor) setColor(seekBar,color); } public void onStartTrackingTouch(SeekBar seekBar) { mTrackingText.setText("seekbar_tracking_on"); } public void onStopTrackingTouch(SeekBar seekBar) { mTrackingText.setText("seekbar_tracking_off"); } } main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <SeekBar android:id="@+id/seek" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="0" android:secondaryProgress="0" /> <TextView android:id="@+id/progress" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/tracking" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> pblue.xml(pred.xml and pgreen.xml are different only for the progress layer): <?xml version="1.0" encoding="utf-8"?> <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="#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="#ff0099CC" android:centerColor="#ff3399CC" android:centerY="0.75" android:endColor="#ff6699CC" android:angle="270" /> </shape> </clip> </item> </layer-list> Can someone help me? thanks -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en