I'm creating a custom Seekbar with thumb.
Currently it looks like this:
http://imgur.com/ofVc7eg
The problem:
The drawable i'm using for the thumb (an oval shape) clips over the progressbar.
My code look like this:
The Seekbar in the layout:
<SeekBar
android:background="#android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="#xml/thumb_image"
android:progressDrawable="#xml/progress"
android:max="100"/>
progress.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">
<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="#FFD700"
android:centerColor="#FFB90F"
android:centerY="0.75"
android:endColor="#FFA500"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
thumb_image.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:color="#android:color/transparent">
<solid android:color="#android:color/black" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
try
android:splitTrack="false"
in the seek bar
For reference see this thread
Custom seekbar thumb not transparent on Lollipop API21
What worked for me was setting android:clipChildren="false" on the parent view.
I have used android:thumbOffset="-0dp" and assigned custom thumb and its working fine. Implemented many solutions but they are not working perfectly because of custom thumb drawable but this one is straightforward with minimal changes.
Related
I'm using a custom drawable for my progress bar:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="15dp" />
<solid android:color="#color/light_grey" />
</shape>
</item>
<item android:id="#android:id/progress" >
<clip>
<shape>
<corners android:radius="15dp" />
<solid android:color="#color/indigo" />
</shape>
</clip>
</item>
</layer-list>
and it looks like:
Now, the background appears with a round corner, but the progress (inside) is straight, and I want to make it round too, like this:
I googled but didn't find any solution.
Any ideas on how can I achieve this round corner on progress?
Thanks!
you can see example of view here
you can modify the color and size of the thumb and seekbar to do what you want.
This solution was the only way i could do this.
Hope this help
this is my seekbar :
<SeekBar
android:id="#+id/simpleProgressBar"
android:layout_width="fill_parent"
android:layout_height="12dp"
android:max="100"
android:progress="0"
android:background="#null"
android:shape="oval"
android:splitTrack="false"
android:progressDrawable="#drawable/progress_background"
android:secondaryProgress="0"
android:thumbOffset="10dp"
android:thumb="#drawable/oval_seekbar_thumb" />
this is (progress_background.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">
<shape android:shape="rectangle">
<corners android:radius="5dp" />
<gradient
android:angle="270"
android:endColor="#color/grey_line"
android:startColor="#color/grey_line" />
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape android:shape="oval">
<corners android:radius="5dp" />
<gradient
android:angle="270"
android:endColor="#color/blue"
android:startColor="#color/blue" />
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape android:shape="rectangle">
<corners android:radius="90dp" />
<gradient
android:angle="90"
android:endColor="#color/colorPrimaryDark"
android:startColor="#color/colorPrimary" />
</shape>
</clip>
</item>
and this is the thumb (oval_seekbar_thumb.xml) :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#ffffff" />
<stroke android:color="#color/colorPrimaryDark" android:width="3dp"/>
<size android:height="12dp" android:width="12dp"/>
</shape>
</item>
</selector>
The height of the thumb should be same as the height of the seekbar to look properly.
Replace the <clip> tag with <scale android:scaleWidth="100%">. This should give the curved edges to secondary progress
I know maybe it is obsolete question,but, just remove <clip> tag.
I have set the progressbar style using the below code.
I have declared the progressbar widget:
<ProgressBar
android:id="#+id/loadProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="20dip"
android:max="100"
android:progressDrawable="#drawable/load_progress"
android:progress="0" />
defined the "#drawable/load_progress"
<?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/background_bk">
</item>
<item
android:id="#android:id/progress"
android:drawable="#drawable/progress_bk">
</item>
</layer-list>
defined the "#drawable/background_bk" (it is red)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="0"
android:endColor="#ff0000"
android:startColor="#ff0990" />
<stroke
android:width="1dp"
android:color="#ff0000" />
</shape>
defined the #drawable/progress_bk (it is green)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="0"
android:endColor="#00ff00"
android:startColor="#00ff00" />
<stroke
android:width="1dp"
android:color="#00ff00" />
</shape>
The progressbar always shows totally green (which is how it should appear when the progress value is 100), even if I set the progress value to less than 100. Any input would be appreciated.
Here is what I did to have a progress bar that was green with clear background:
android:background="#color/white"
android:progressBackgroundTint="#color/white"
android:progressTint="#color/green_light"
Finally, I find a easy solution.
1
you can find the default drawable xml file in your folder
"SDK_path\platforms\android19\data\res\drawable"
Overthere you can find many default style of many widgets.
2
and get the file "progress_horizontal.xml".
the codes in that file is:
<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="#ffffd300"
android:centerColor="#ffffb600"
android:centerY="0.75"
android:endColor="#ffffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
3
you can easily change the color of the "progress color" and "background color".
Why my prograssbar is not shown as a moving prograssbar? It is just a white bar there .
Here is my code , Please help me with this,thank you !
Ive tried to change the color code but still not working .
I want it be something like this :
http://developer.android.com/design/media/progress_themes.png
But in this color :002a5c
<?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="0dip" />
<gradient
android:angle="90"
android:centerColor="#F8F8FF"
android:centerY="0.75"
android:endColor="#ffffff"
android:startColor="#C0C0C0" />
<stroke
android:width="25dp"
android:color="#002a5c" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="0dip" />
<gradient
android:angle="90"
android:endColor="#002a5c"
android:startColor="#002a5c" />
<stroke
android:width="25dp"
android:color="#002a5c" />
</shape>
</clip>
</item>
</layer-list>
Please help to create horizontal progress bar like this
Set style for horizontal progress bar
style="?android:attr/progressBarStyleHorizontal"
Create custom progress drawable: green_progress_drawable.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">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#779d9e9d"
android:centerColor="#995a5d5a"
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="#33FF33"
android:endColor="#008000"
android:angle="270" />
</shape>
</clip>
</item>
</layer-list>
My progressbar code:
<ProgressBar
android:progressDrawable="#drawable/green_progress_drawable"
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/mf_progress_bar"
app:layout_widthPercent="80%"
app:layout_heightPercent="8%"
app:layout_marginTopPercent="5%"
android:layout_gravity="center_horizontal"
/>
Code credit to #Ryan https://stackoverflow.com/a/5745923/3879847
My output:
I hope this post maybe helpful for someone..
You do not need a custom progress bar. Use style="#android:style/Widget.ProgressBar.Horizontal" in your layout xml file. You will also need to use
ProgressBar.incrementProgressBy(int progress);
See Android Developers|ProgressBar
and when it calls setProgress(20) , how does it know that it is the green color will increase instead of the gray color?
pb.setProgress(0);
pb.setProgressDrawable(getResources().getDrawable(R.drawable.green_progress));
pb.setProgress(20);
Here is the green_progress.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">
<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/progress">
<clip>
<shape>
<corners
android:radius="5dip" />
<gradient
android:startColor="#color/greenStart"
android:centerColor="#color/greenMid"
android:centerY="0.75"
android:endColor="#color/greenEnd"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
It's thanks to the #android:id/progress, a special id which is known by ProgressDialog class. So, in ProgressDialog, the code know which shape it has to expand and which one it has to reduce, during the progression.