先去布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/seekbar" android:max="100" android:progress="50" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tv1" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tv2" /><!-- 两个文本为状态显示 --> </LinearLayout>
两个状态随便一扔个地方。。。
然后java文件
package com.example.deemo; import android.app.Activity; import android.os.Bundle; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; public class MainActivity extends Activity implements OnSeekBarChangeListener{ private SeekBar seekbar; private TextView tv1; private TextView tv2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); seekbar=(SeekBar) findViewById(R.id.seekbar); tv1=(TextView) findViewById(R.id.tv1); tv2=(TextView) findViewById(R.id.tv2); seekbar.setOnSeekBarChangeListener(this); } //数值改变 @Override public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) { // TODO Auto-generated method stub tv1.setText("ing"); tv2.setText("now"+progress); } //开始拖动 @Override public void onStartTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub tv1.setText("start"); } //停止拖动 @Override public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub tv1.setText("end"); } }
简单暴力
然后自定义样式的话在seekbar标签里用style,然后进入style文件修改。