SeekBar's thumb only appears when touched

I want to have a SeekBar with a thumb that appears as the user interacts with it (by dragging it to the desired location) and disappears after the interaction.

Today my SeekBar looks like this:

<SeekBar android:id="@+id/seekBar_volume"
        android:layout_width="fill_parent"
        android:progressDrawable="@drawable/custom_player_seekbar_background"
        android:paddingTop="10px" 
        android:paddingBottom="10px" 
        android:thumb="@drawable/myThumb" 
        android:paddingLeft="30px" 
        android:paddingRight="30px" 
        android:minHeight="6dip"
        android:maxHeight="6dip" 
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"/>

The thumb position only changes with user interaction (something like a "volume control").

seekBarVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        public void onStopTrackingTouch(SeekBar arg0) {

        }

        public void onStartTrackingTouch(SeekBar arg0) {

        }

        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
           audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
        }
});

I tried to use the selector 's feature, setting the thumb's drawable with a customized xml to handle the different states I wanted, but it didn't work =/

Thanks in advance for any help


感谢罗曼盖伊和一些错误修复,它完美地工作...

seekBarVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

    public void onStopTrackingTouch(SeekBar arg0) {
        // TODO Auto-generated method stub
        seekBarVolume.setThumb(null);
    }

    public void onStartTrackingTouch(SeekBar arg0) {
        seekBarVolume.setProgress(0);

        drawable = getResources().getDrawable(R.drawable.bt_do_player);
        final int quarterHeight = drawable.getIntrinsicHeight()/4;
        final int halfWidht = drawable.getIntrinsicWidth()/2;

        drawable.setBounds(new Rect(-halfWidht,
                -quarterHeight,
                halfWidht,
                3*quarterHeight));
        seekBarVolume.setThumb(drawable);

        seekBarVolume.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));


    }

     public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
         audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
     }
});
链接地址: http://www.djcxy.com/p/64334.html

上一篇: 在SeekBar中设置新的缩略图会删除进度背景

下一篇: SeekBar的拇指只有在触摸时才会出现