<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<SeekBar
android:id="@+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/seekbar_bg"
android:thumb="@drawable/thumb"
android:thumbOffset="0dp" />
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="请按住滑块,拖动到最右边"
android:textColor="#888888"
android:textSize="14dp" />
</RelativeLayout>
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--seekBar背景-->
<item android:id="@android:id/background">
<!--形状-->
<shape android:shape="rectangle">
<!--大小-->
<size android:height="29dp" />
<!--圆角-->
<corners android:radius="2dp" />
<!--背景-->
<solid android:color="#E7EAE9" />
<!--边框-->
<stroke
android:width="1dp"
android:color="#C3C5C4" />
</shape>
</item>
<!--seekBar的进度条-->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="2dp" />
<solid android:color="#7AC23C" />
<stroke
android:width="1dp"
android:color="#C3C5C4" />
</shape>
</clip>
</item>
</layer-list>
public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
private TextView tv;
private SeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
seekBar = (SeekBar) findViewById(R.id.sb);
seekBar.setOnSeekBarChangeListener(this);
}
/**
* seekBar进度变化时回调
*
* @param seekBar
* @param progress
* @param fromUser
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (seekBar.getProgress() == seekBar.getMax()) {
tv.setVisibility(View.VISIBLE);
tv.setTextColor(Color.WHITE);
tv.setText("完成验证");
} else {
tv.setVisibility(View.INVISIBLE);
}
}
/**
* seekBar开始触摸时回调
*
* @param seekBar
*/
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
/**
* seekBar停止触摸时回调
*
* @param seekBar
*/
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (seekBar.getProgress() != seekBar.getMax()) {
seekBar.setProgress(0);
tv.setVisibility(View.VISIBLE);
tv.setTextColor(Color.GRAY);
tv.setText("请按住滑块,拖动到最右边");
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有