Android如何使用SeekBar
扫描二维码
随时随地手机看文章
activity_mian.xml 部分
seek.xml
package com.example.administrator.seekbar; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.SeekBar; import android.widget.TextView; public class MainActivity extends ActionBarActivity { private SeekBar seekBar; private TextView text1; private TextView text2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); seekBar = (SeekBar)findViewById(R.id.seekBar); text1 = (TextView)findViewById(R.id.text1); text2 = (TextView)findViewById(R.id.text2); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { text1.setText("正在拖动"); text2.setText("当前数值:"+progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { text1.setText("开始拖动"); } @Override public void onStopTrackingTouch(SeekBar seekBar) { text1.setText("停止拖动"); } }); } }