如何在“onCreate"方法之后更改可绘制的 Android SeekBar Thumb? [英] How can I change the Android SeekBar Thumb drawable after 'onCreate' method?

查看:54
本文介绍了如何在“onCreate"方法之后更改可绘制的 Android SeekBar Thumb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试更改 android 中搜索栏的拇指的可绘制图像.在 onCreate() 方法中,我可以使用以下

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

但是,在调用 onCreate 方法后,我尝试使用具有相同方法的不同 drawable 再次更改它,并且拇指消失了.api 描述是设置将在 SeekBar 中进度表末尾绘制的拇指".这是否意味着图像将被绘制出屏幕(如果我用我的搜索栏'fill_parent')?我尝试更改偏移量但无济于事,还有其他人遇到过这个问题吗?或者知道如何在进度变化时更改拇指图像?

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?

我还应该提到,我将我的搜索栏的背景可绘制设置为一个空白的 xml 文件(即没有背景图像).

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

推荐答案

对我有用的一件事是使用 setBounds 方法但是我遇到的问题是在我的应用程序中它重置了拇指的位置可绘制回到行首.我不知道这是否与我的代码的工作方式有关,或者无论它如何实现都会发生.

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

这篇关于如何在“onCreate"方法之后更改可绘制的 Android SeekBar Thumb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆