[安卓] 5、SeekBar拖动条

时间:2021-06-25 19:50:37

[安卓] 5、SeekBar拖动条


越来越发现这些控件用法大同小异了,这里注意几个函数:seekBar.setSecondaryProgress(0);设置初始进度为0,总共为0~99,对其监听用setOnSeekBarChangeListener。

 public class MainActivity extends Activity {
private SeekBar seekBar;
private TextView tv; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
seekBar = (SeekBar) findViewById(R.id.seekbar);
tv = (TextView) findViewById(R.id.tv);
seekBar.setSecondaryProgress(0);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
//当用户对拖动条的拖动的动作完成时触发
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
tv.setText("<拖动条>完成拖动");
}
//当用户对拖动条进行拖动时触发
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
tv.setText("<拖动条>拖动中...");
}
//当拖动条的值发生改变的时触发
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tv.setText("当前<拖动条>的值为:"+progress);
}
});
}
}

本文链接:http://www.cnblogs.com/zjutlitao/p/4229808.html

更多精彩:http://www.cnblogs.com/zjutlitao/