1 SeekBar简介
SeekBar是进度条。我们使用进度条时,可以使用系统默认的进度条;也可以自定义进度条的图片和滑块图片等。
2 SeekBar示例
功能:手动拖动进度条,TextView中文字显示进度的改变。
1 public class MainActivity extends AppCompatActivity { 2 private SeekBar sb; 3 private TextView tv; 4 5 @Override 6 protected void onCreate(Bundle savedInstanceState) { 7 super.onCreate(savedInstanceState); 8 setContentView(R.layout.activity_main); 9 sb=(SeekBar)findViewById(R.id.sb); 10 tv=(TextView) findViewById(R.id.tv); 11 sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 12 @Override 13 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 14 tv.setText("The progress is "+progress+"%"); 15 } 16 17 @Override 18 public void onStartTrackingTouch(SeekBar seekBar) { 19 20 } 21 22 @Override 23 public void onStopTrackingTouch(SeekBar seekBar) { 24 25 26 } 27 }); 28 } 29 }
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:orientation="vertical" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 tools:context="com.zhangmeng.www.seekbar.MainActivity"> 9 <SeekBar 10 android:id="@+id/sb" 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content"/> 13 <TextView 14 android:id="@+id/tv" 15 android:layout_width="match_parent" 16 android:layout_height="wrap_content"/> 17 18 19 20 </LinearLayout>