How to add number scale on android SeekBar

泪湿孤枕 提交于 2019-12-04 09:53:26
Amit Gupta

For drawing text over the seekbar thumb use this function

  public BitmapDrawable writeOnDrawable(int drawableId, String text){

        Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
        Paint paint = new Paint(); 
        paint.setStyle(Style.FILL);  
        paint.setColor(Color.BLACK); 
        paint.setTextSize(20); 
        Canvas canvas = new Canvas(bm);
        canvas.drawText(text, 0, bm.getHeight()/2, paint);

        return new BitmapDrawable(bm);
    }

This function will call as

seekbar.setThumb(writeOnDrawable(R.drawable.thumbimage, mytext)); put thumbimage.png file in res/drawable/ and 'mytext' is the string which you want to write on top of that drawable

For complete conversation see the below link

how to set the seek bar thumb with a layout or with a TextView?

Hope this will be helpful to you.

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