我正试图从代码中改变SeekBar的拇指。当有人点击并实施时我想改变
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
seek.setThumb(getResources().getDrawable(R.drawable.red_rect));
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
}
});
开始时我有默认拇指,当我点击它时应该更改为red_rect,但是当我点击时,拇指就会消失。有人可以帮我解决这个问题吗?
答案 0 :(得分:3)
从Resources:
获取后,需要在Drawable上调用setBounds()final Drawable d = getResources().getDrawable(R.drawable.thumb);
d.setBounds(new Rect(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()));
slider.setThumb(d);
来自http://www.mail-archive.com/android-developers@googlegroups.com/msg164344.html