https://www.jianshu.com/p/05ef48b777cc
https://www.cnblogs.com/mengdd/p/5590634.html
http://www.cocoachina.com/articles/80555
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.SeekBar;
public class MySeekBar extends SeekBar {
public MySeekBar (Context context) {
super(context);
}
public MySeekBar (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MySeekBar (Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas c) {
super.onDraw(c);
int thumb_x = (int) (( (double)this.getProgress()/this.getMax() ) * (double)this.getWidth());
float middle = (float) (this.getHeight());
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(20);
c.drawText(""+this.getProgress(), thumb_x, middle, paint);
}
}
<yourPackageName.MySeekBar
android:id="@+id/my_seek_bar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="26dp"
android:max="10"/>
seekBar = (MySeekBar) findViewById(R.id.my_seek_bar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
网友评论