i have a trouble with custom seekBar .I used http://android-holo-colors.com/ to give images of seekBar .The problem is a vague beginning of seekBar . How can i solve this problem?!
ScreenShot:
this code (i check , images are the same as the default except for colors.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:drawable="#drawable/scrubber_track_red" />
<item android:id="#android:id/secondaryProgress">
<scale android:scaleWidth="100%"
android:drawable="#drawable/scrubber_secondary_red" />
</item>
<item android:id="#android:id/progress">
<scale android:scaleWidth="100%"
android:drawable="#drawable/scrubber_primary_red" />
</item>
</layer-list>
and SeekBar
<SeekBar
android:id="#+id/seekTrack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progressDrawable="#drawable/scrubber_progress_red"
android:thumb="#drawable/scrubber_control_red"
android:indeterminate="false"
android:layout_weight="1"
style="?android:attr/progressBarStyleHorizontal"/>
Images i got from aforementioned service (android holo colors)
Check your drawables, there's probably a gradient in there somewhere as opposed to a solid color. I'd guess that the problem is in #drawable/scrubber_progress_red. Replace it temporarily with something like #android:color/holo_green_light. If the gradient goes away, we'll know that the scrubber_progress_red drawable is the problem.
Also, what is the name of the file that the layer-list is in?
Related
I'm trying to implement SeekBar with custom progress and backround.
Seekbar
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:id="#+id/seekBar"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:thumbOffset="0dp"
android:maxHeight="6dp"
android:tag="seekbar"
android:thumb="#drawable/circle_seekbar_player_fragment" android:progressDrawable="#drawable/styled_progress_player_fragment"/>
styled_progress_player_fragment.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/seekbar_backgroun">
</item>
<!--<item android:id="#android:id/secondaryProgress">
<scale
android:drawable="#drawable/rounded_corners_seekbar_transparent"
android:scaleWidth="100%" />
</item>-->
<item
android:id="#android:id/progress">
<scale
android:drawable="#drawable/seekbar_progres"
android:scaleWidth="100%"/>
</item>
</layer-list>
Background seekbar_backgroun.9.png
Progress image seekbar_progres.9.png
In 9patch window it is scaled as i want:
But in my app it's acting strange or maybe i'm not doing smthng right
Can you help me so my seekbar look fine
EDIT
Problem solved. The problem was that when i use ninepatch it uses resolurion in px not in dp, that's why it was scaling down
I fixed it by placing this ninepatch images to xxhdpi folder
I am trying to set a custom background to the spinner:
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:background="#drawable/spinner_bg"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
spinner_bg.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#ff0000"/>
<item android:drawable="#00ff00"/>
</selector>
I saw a lot of tutorials and articles that are doing such thing, but in my case it
somehow doesn't work, I just got plain text without any states and backgorund, if I set color or 9-patch to the background all works fine. What am I doing wrong?
Edit: I have tried all suggestions, but it doesn't help, also Android Studio pointing out that something is wrong, but no hint available.
Edit2: I found the problem. I missed .xml extension for the spinner_bg file in my source. Also Mou had right correction that I should use drawable instead of color, so I marked his answer as correct.
The problem is in spinner_bg.xml.
android:drawable must be a reference to a drawable and not a color.
Try creating a shape drawable or another drawable (9-path) and setting it correctly in the xml.
EDIT:
Something like this:
spinner_bg_color.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#FFFF0000"/>
</shape>
And setting this drawable like background drawable in spinner_bg.xml
Change
android:drawable="#00ff00"
to
android:color="#00ff00"
like so:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ff0000"/>
<item android:color"#00ff00"/>
</selector>
I made a customised seekbar that looks like this
the thing is that it is pretty hard to grab the slider. so what i wanted to to is to increase the hitbox of the thumb to make it easier. i tried a few things, but always messed up the seekbar look. any ideas how i could do that?
layout.xml
<SeekBar
android:id="#+id/xxx"
style="#style/SeekBar"
android:layout_width="#dimen/pixel_130dp"
android:layout_below="#+id/name_textview"
android:layout_centerHorizontal="true" />
styles.xml
<style name="SeekBar">
<item name="android:layout_height">#dimen/pixel_20dp</item>
<item name="android:maxHeight">#dimen/pixel_20dp</item>
<item name="android:minHeight">#dimen/pixel_20dp</item>
<item name="android:thumb">#drawable/seek_bar_thumb</item>
<item name="android:paddingLeft">#dimen/pixel_5dp</item>
<item name="android:paddingRight">#dimen/pixel_5dp</item>
<item name="android:paddingTop">#dimen/pixel_2dp</item>
<item name="android:paddingBottom">#dimen/pixel_2dp</item>
<item name="android:progressDrawable">#drawable/seek_bar_progress_drawable</item>
</style>
seek_bar_thumb.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<size
android:height="#dimen/pixel_16dp"
android:width="#dimen/pixel_25dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:drawable="#drawable/slider_thumb"/>
</layer-list>
Alright, since there are apparently no smarter ways to do that, here is what I did now; only solution I found was to add a transparent area around the thumb image. I doubled its size and added the thumbOffset parameter to the Seekbar. That doesn't seem to be the best solution, but at least it works in my case.
The TouchDelegate class seems to be a good place to start.
See this tutorial on how you can use it.
I want to create a bar like this initially when progress is zero it will be a fade in color but and as progress goes on it will become bright on that part(This is best I can explain) main thing is i want bar to show all colors at the same time.
Clip your "on" drawable:
over your "off" drawable:
by using res/drawable/custom_progress_drawable.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Background -->
<item
android:id="#android:id/background"
android:drawable="#drawable/custom_progress_bar_off"/>
<!-- Secondary progress - this is optional -->
<item android:id="#android:id/secondaryProgress">
<clip android:drawable="#drawable/custom_progress_bar_secondary" />
</item>
<!-- Progress -->
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/custom_progress_bar_on" />
</item>
</layer-list>
From an Activity, use
Drawable progressDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.custom_progress_drawable, getTheme());
myProgressBar.setProgressDrawable(progressDrawable);
or in xml, use
android:progressDrawable="#drawable/custom_progress_drawable"
And here's the result when using android:max="10" in xml:
It's a little bit off, but you could use setMax() with something more like 10000 and do some offsetting calculations when calling setProgress() to make it cleaner.
Finally! I went on a mission to figure this out for you, so if this suffices, feel free to give me that bounty, haha.
Try using this in your layout:
<View android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".20"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="0.62">
<View android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".03"/>
<ProgressBar style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.94"
android:progressDrawable="#drawable/progressmask"
android:progress="0"
android:max="10"
android:rotation="180"/>
<View android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".03"/>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".18"/>
</LinearLayout>
which references this drawable (progressmask.xml):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="50dip" />
<gradient android:startColor="#00000000" android:endColor="#00000000" android:angle="270" />
<stroke android:width="1dp" android:color="#00000000" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="50dip" />
<gradient android:startColor="#aa000000" android:endColor="#aa000000"
android:angle="270" />
<stroke android:width="1dp" android:color="#00000000" />
</shape>
</clip>
</item>
</layer-list>
and this image (colorprogress.png)
What it does is set the image as the background of a linearlayout, which contains a progressbar. The progressbar adds a semi-transparent black mask to the image to make it appear that the lights are off.
NOTE: In order to get this affect, I had to monkey with the progress bar (i.e. flip it, and set it to only 10 intervals. You will have to do some math to get the progress to line up with the image. i.e. setprogress((100-trueprogress)/10). Sorry I did not do this part for you.
This is what it will look like at progress 50% (the small x's and triangles will disappear on the device)
I hope this answers your question!
Like already suggested i think you should go for an layer-list and set multiple drawables then.
Main problem on this is that i need to be resizeable. An fixed size solution would be quite easy to implement.
You can't actually set the progress bars to different colors. You can however use only the on drawable and get the effect that you want. You could just apply a layer mask. What I mean is add a Relative layout which is initially say dark grey throughout i.e the gradient has only ONE color which is dark gray. Now, use code to set the gradient color on the left programmatically. Obviously the color on the left is going to be transparent. Learn more about Linear Gradients. That's about it. You just need to calculate the position from where the right gradient starts, rather where the left gradient(transparent)ends.
This method is slightly flawed and may not work on ALL devices.
The flawless method would be to create multiple .9png images and set the drawable of the progress dialog programmatically every time.
I have set thumb image of a seek bar but my thumb looks little below of seek bar. How to set thumb at proper position of a seekbar. Have a look on the attached image
<SeekBar android:id="#+id/PP_Player_SeekBar"
android:thumb="#drawable/music_player_playerhead"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:progressDrawable="#drawable/seekbar_drawable_xml_background"
android:layout_width="236dip"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginTop="47dip"></SeekBar>
Thanks
Sunil Kumar Saoo
Set minHeight and maxHeight same as the height of seekbar. eg
<SeekBar
android:id="#+id/PP_Player_SeekBar"
android:thumb="#drawable/music_player_playerhead"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:progressDrawable="#drawable/seekbar_drawable_xml_background"
android:layout_width="236dip"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginTop="47dip"
android:minHeight="11dip"
android:maxHeight="11dip" />
See the following url
http://qtcstation.com/2011/05/android-how-to-fix-seekbar-bar-thumb-centering-issues/
In fact, it is enough to define maxHeight to a big number like 1000dp.
This also has the benefit of working with height=wrap_content and height=match_parent.
For me, the issue is more related to the vertical centering of the background (track drawable). This is the flawed drawable code I used originally (which generated the problem), as suggested by Android developer and other StackOverflow entries:
<item
android:id="#android:id/background"
android:drawable="#drawable/seekbar_track"/>
<item android:id="#android:id/secondaryProgress">
<scale
android:drawable="#drawable/seekbar_progress2"
android:scaleWidth="100%" />
</item>
<item android:id="#android:id/progress">
<scale
android:drawable="#drawable/seekbar_progress"
android:scaleWidth="100%" />
</item>
The problem here is the first item, which relates to the background of the SeekBar. Many entries will tell you to set the layout_minHeight feature to some large value to avoid a vertical spatial disconnect between the thumb and its track. This was not the solution for me - when viewed on a tablet, the background was still drawing to its smaller phone-based size - so the track was consistently positioned well above the center of the SeekBar track. The solution is to remove this entry in the SeekBar drawable, so it now looks like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/secondaryProgress">
<scale
android:drawable="#drawable/seekbar_progress2"
android:scaleWidth="100%" />
</item>
<item android:id="#android:id/progress">
<scale
android:drawable="#drawable/seekbar_progress"
android:scaleWidth="100%" />
</item>
</layer-list>
Then, in the style definition of the SeekBar, set the layout_background to the the track drawable. Mine looks like this:
<style name="styleSeekBar" parent="#android:style/Widget.SeekBar">
<item name="android:padding">#dimen/base_0dp</item>
<item name="android:background">#drawable/seekbar_track</item>
<item name="android:progressDrawable">#drawable/abratingbar</item>
<item name="android:minHeight">#dimen/base_29dp</item>
<item name="android:maxHeight">#dimen/base_29dp</item>
<item name="android:layout_marginLeft">#dimen/base_10dp</item>
<item name="android:layout_marginRight">#dimen/base_10dp</item>
<item name="android:layout_marginTop">#dimen/base_10dp</item>
<item name="android:layout_marginBottom">#dimen/base_10dp</item>
<item name="android:scaleType">fitXY</item>
</style>
(Previously, the background setting here was just a color [white].).
This is the entry in my layout, which uses both the style and the drawables:
<SeekBar
android:id="#+id/seekbar_page_number"
style="#style/styleSeekBar"
android:layout_width="match_parent"
android:layout_height="#dimen/base_29dp"
android:minHeight="#dimen/base_29dp"
android:maxHeight="#dimen/base_29dp"
android:layout_marginLeft="#dimen/base_230dp"
android:layout_gravity="bottom|right"
android:progress="1"
android:max="20"
android:progressDrawable="#drawable/abseekbar"
android:thumb="#drawable/abseekbar_thumb"/>
So, to summarize, do not set the background (track) feature in your custom SeekBar drawable, set it in the layout_background feature of your custom SeekBar style. This ensures the track is always vertically centered in a horizontal SeekBar.
I simply resolved the misaligned horizontal seekbar thumb by setting layout_height of the seekbar to wrap_content instead of match_parent