I have a problem with seekbars. They work without issues until I try and do the following:
seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.seek_bar));
I even tried using a color only instead of a drawable resource. Same issue. The problem is when I do set the drawable, I see that the Seekbar drawable is a bit shorter (from start and end) and the thumb icon can go beyond it.
Also, I have noticed that the thumb icon itself has a white background surrounding it (not transparent). I even tried setting a vector drawable for the thumb, and the thumb went beyond the boundaries of seekbar (part of the thumb was hidden).
Could someone explain this behavior. I have tried searching for around three hours now without luck. I even tried the solution from:
How to set Android SeekBar progress drawable programatically
Which has the same issue for me.
Thank you.
To get rid of the non-transparent background I have used:
seekBar.setSplitTrack(false);
To make the thumb not go beyond the boundaries, I have shrunk the thumb. It is not perfect but it works.
Related
I made a TextView which has attributes of background, gravity and so on.
and i made a drawable resource file for the TextView's background.
and this is the xml.
and i added the drawable resource into background of the TextView.
but the problem is, the background doesn't fit in Textview's bound.
please look at this photo.
there is a gap very slightly.
the background color area is upper than TextView's area.
so i tried to use includeFontPadding attribute but it didn't work.
how can i fix it?
I would advise you to check this on real device/emulator, not on preview in AS. use Show Layout Bounds option from developer options for verification, make some full-resolution screen shot and check on it. it will be properly placed
content of any View, including its background, is always places inside its bounds. really, always, its just impossible to get outside with a single pixel (due to layout building and drawing mechanism)
Nothing is wrong with the code. In the Design Editor, it shows like this when we use any background drawable with any view. There is not any kind of a glitch.
I have a SeekBar that I'm trying to implement custom styling on. The edges of my progressDrawable have rounded corners which I think looks great, however when i drag the thumb to the edges it looks strange.
This is how the SeekBar looks when I use an "in the middle" progress value like 80.
And this is how the start and end look when I use a progress value of 0 or 100 respectively. You can see how the rounded corners look strange due to the way the thumb goes all the way to the end of the SeekBar.
I'm looking for a way to get the thumb to STOP at around 16dp before the end of the SeekBar, but for the progressDrawable to still fill it in as if it had gone to 100.
I also just noticed that the thumb seems to cut off half way through it's drawable. That is not related to what I'm asking, so I'm trying to avoid any confusion there.
On Android, I have a header with a background image (Random image according to API).
On this header I have texts with some data. My text is every time black but sometimes image is black too. So, we can't see the text.
I'm looking for library or snippet for resolve this problem.
Thanks.
You can use the palatte library for this. Please see the following:
https://developer.android.com/reference/android/support/v7/graphics/Palette.html
https://developer.android.com/training/material/palette-colors.html
I encoutered this problem months ago and was not really sure how to approach it. First of all you need to use a Layout where you can put View over View for example Relative or Frame. After that you need to make the ImageView thats behind the TextView to be a little bit Lighter or Darker (like a shade) at the place of your TextView so you can choose a color for your text which will always be readable since the shade will be in contrast with the text. What you can do is put something behind the TextView and the ImageView which will be Light or Dark and make the ImageView a little bit transparent using set.alpha(int) if i remember correctly. So at this point you will have transparent image with a light or dark rectangle behind it. It will be visible that the part where you have the rectangle is darker/lighter. Then you put your TextView there with contrast color to the Rectangle and you will always be able to see it. It is kind of complicated, but it will work. Hope it helps.
I think palatte is not available for android. So glide will be a better option. Link
Currently I am attempting to change the drawable image of the Thumb of a seekbar in android. In the onCreate() method I am able to effectively change the thumb using the following
mSeekBar.setThumb(myDrawable);
However, after the onCreate method is called, I attempt to change it again using a different drawable with the same method and the thumb disappears. The api description is 'Sets the thumb that will be drawn at the end of the progress meter within the SeekBar.' Does this mean that the image will be drawn off screen (if i 'fill_parent' with my seekbar)? I have tried changing the offset with no avail, has anyone else run into this issue? Or know how to change the thumb image while the progress is changing?
I also should mention that I am setting my background drawable for the seekbar to a blank xml file (i.e. to not have a background image).
One thing that has partially worked for me is to use the setBounds method however the problem I have run into is that in my app it resets the position of the thumb drawable back to the beginning of the line. I don't know if this is related to how my code works or if it happens no matter how it is implemented.
Drawable myThumb = getResources().getDrawable(R.drawable.slider_button);
myThumb.setBounds(new Rect(0, 0, myThumb.getIntrinsicWidth(),myThumb.getIntrinsicHeight()));
skbr.setThumb(myThumb);
I have set negative paddings on my custom seekbar so that the round thumb image can go outside the bar, but the thumb isn't rendered out there, is there anyway to force the thumb to be drawn outside those bounds?
Sorry guys, I'm new to Android development, and have been tasked with fixing an existing application. The problem is that we have a custom rounded looking track bar, which consists of two rounded 'end cap' images and a 1 px background that is tiled to create the seekbar. As far as I can tell there was never one image that could be set as the background of a normal SeekBar, which is why a custom one was created.
The thumb is a circle and needs to 'fit' into the end caps - the three pieces of the bar are in a relative layout. Right now I'm kind of unclear as to how the 1 px background png gets stretched as the seekbar bg, otherwise I would try to tack on the two endcaps onto that drawable some how ... ?
Please let me know if this was unclear and I'll try to post any followup info. Thanks in advance for any advice!!
Oh, I'm using Android 2.1 if that's relevant to anyone's interests :)
This is what it looks like when the thumb all the way over - outside of the seekbar. Ideally what I need is for the thumb to be shown as 'inside' the endcap image :-/
I was having the same problem, my thumb is very big length wise and it kept being cut off. Make sure that you set the offset property AFTER you set the drawable for your thumb, like this:
seek.setThumb(Main.app.getResources().getDrawable(R.drawable.thumb));
seek.setThumbOffset(15);
This will set the correct offset when your thumb is very long.
Try to change the thumb offset property, after that it will not go off from the seek bar
I just ran into this issue. I was able to get satisfactory results by using android:paddingLeft and android:paddingRight within the XML.