How can I change the Android SeekBar Thumb drawable after 'onCreate' method?

≡放荡痞女 提交于 2019-12-23 15:54:17

问题


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).


回答1:


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);


来源:https://stackoverflow.com/questions/3882992/how-can-i-change-the-android-seekbar-thumb-drawable-after-oncreate-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!