问题
If anybody knows what i'm doing wrong please let me know. I created an android app and I am trying to change the default color of the seekbar from yellow to any other color. I created an xml file located in all 3 drawables and ran the project but the color of the seekbar still isnt changing color. Below is the code me and a fellow mate from irc have been working on.
<?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="#FF0000"
android:centerColor="#FF0000"
android:centerY="0.75"
android:endColor="#FF0000"
android:angle="270" />
</shape>
</clip>
</item>
</layer-list>
This is my java code
SeekBar seekBar = (SeekBar)findViewById(R.id.seekbar);
final TextView seekBarValue = (TextView) findViewById(R.id.seekbarvalue); //filling seekbar
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
seekBarValue.setText(String.valueOf(progress+1998)); //sets the date to seekBar when in motion
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
//TO DO Auto-Generated Method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
//TO DO Auto-Generated Method stub
}
回答1:
Okay so basically all i needed to do is go into my main.xml file not the one located in the drawables folder and then make sure to put
android:progressDrawable="@drawable/myprogress"
where myprogress is the name of my .xml file located in the drawables folder.
来源:https://stackoverflow.com/questions/5314488/changing-default-seekbar-color