Android SeekBar thumb Customization

前端 未结 3 730
故里飘歌
故里飘歌 2021-01-03 05:08

I want to hide bar and only want to show thumb. I did it with max-height=0dip but it did not completely work. I also want to set text on thumb and create thumb with multiple

相关标签:
3条回答
  • 2021-01-03 05:23
      SeekBar seekbar = new SeekBar(context, attrs);
    
         // ------------- custom thumb
                //----- using resources 
    
        seekbar.setThumb(new BitmapDrawable(BitmapFactory.decodeResource(
             context.getResources(), R.drawable.seekbar_progress_thumb)));
              //----- or using shape drawable
    
    
        ShapeDrawable thumb = new ShapeDrawable(new RectShape());
        thumb.getPaint().setColor(Color.rgb(0, 0, 0));
        thumb.setIntrinsicHeight(-80);
        thumb.setIntrinsicWidth(30);
        seekbar.setThumb(thumb);
    
    0 讨论(0)
  • 2021-01-03 05:26

    Regarding removing the background, I managed to do this in the following way. Here, the blank drawable is a transparent png of 1x1 pixel

        <SeekBar
            android:id="@+id/bar"
            android:layout_width="fill_parent"
            android:layout_height="30dip"
            android:progressDrawable="@drawable/blank"
         />
    

    You can also change the drawable by using:

    android:thumb="@drawable/icon"
    

    To add text, I guess you'll have to create a custom component

    0 讨论(0)
  • 2021-01-03 05:29

    In order to hide the bar, you can set opacity value using hex colors. You just need to add the right prefix. I hid the seekBar using this code:

    android:progressBackgroundTint="#00555555"
    android:progressTint="#00555555"
    

    Where the first two ciphers (i.e. "00") set opaqueness (alpha percentage) and the other six (i.e. "555555") set the color.

    Check this post for more information and a list of hex opacity values: Understanding colors on Android (six characters)

    0 讨论(0)
提交回复
热议问题