How can I change Android SeekBar Thumb after using onCreate method?

I'm currently trying to change the popped Thumb image in the search bar in android. In the onCreate () method, I can effectively change my thumb using the following

mSeekBar.setThumb(myDrawable);

However, after calling the onCreate method, I try to change it again using another method similar to the method, and the thumb disappears. Description api: "Sets the thumb that will be drawn at the end of the progress bar in the SeekBar." Does this mean that the image will be displayed on the screen (if I "fill_parent" using my search bar)? I tried changing the offset to no avail, does anyone else encounter this problem? Or do you know how to change the thumb image while changing the course?

I should also mention that I set my background image to search in an empty xml file (i.e. does not have a background image).

+3
source share
1 answer

One thing that partially worked for me was to use the setBounds method, however the problem I ran into is that in my application it resets the position of the thumb that goes back to the beginning of the line. I don’t know if this is related to the way my code works, or if this 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);
+3
source

Source: https://habr.com/ru/post/1768440/


All Articles