SeekBar的使用
SeekBar监听器为SeekBar.onSeekBarChangeListener
Main
1 package seekdemo.example.administrator.seekbardemo; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.widget.SeekBar; 6 import android.widget.TextView; 7 8 public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener{ 9 private SeekBar seekBar; 10 private TextView textView1; 11 private TextView textView2; 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.main); 16 seekBar= (SeekBar) findViewById(R.id.seekBar); 17 textView1= (TextView) findViewById(R.id.text1); 18 textView2= (TextView) findViewById(R.id.text2); 19 seekBar.setOnSeekBarChangeListener(this); 20 21 } 22 // 正在拖动 23 @Override 24 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 25 textView1.setText("正在拖动"); 26 textView2.setText("当前"+progress); 27 } 28 // 开始拖动 29 @Override 30 public void onStartTrackingTouch(SeekBar seekBar) { 31 textView1.setText("开始拖动"); 32 } 33 // 停止拖动 34 @Override 35 public void onStopTrackingTouch(SeekBar seekBar) { 36 textView1.setText("停止拖动"); 37 } 38 }
layout中main.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 <TextView 6 android:layout_width="match_parent" 7 android:layout_height="wrap_content" 8 android:id="@+id/text1" 9 /> 10 <TextView 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content" 13 android:id="@+id/text2" 14 /> 15 <SeekBar 16 android:layout_width="match_parent" 17 android:layout_height="wrap_content" 18 android:id="@+id/seekBar" 19 android:progress="50" 20 android:max="100" 21 android:thumb="@drawable/btn_radio_on_holo_light"/><!--thumb改变滑块样式--> 22 </LinearLayout>