Android基础控件SeekBar拖动条的使用
1、简介
SeekBar继承ProgressBar,相关属性和三种不同状态下的触发方法:
<!--<SeekBar-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:max="100"-->
<!--android:progress="30"-->
<!--android:id="@+id/seekbar"-->
<!--android:thumb="@mipmap/ic_launcher_round"/>-->//设置滑块的
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override//进度发生改变
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
@Override//按下
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override//放开
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
2、简单使用

这是一个简单自定义的SeekBar,浅绿色是进度条颜色,红色是二级进度条颜色,黄色是背景色!
滑块的selector文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/seekbar_thumb_pressed" /> <item android:state_pressed="false"
android:drawable="@drawable/seekbar_thumb_normal"/>
</selector>
进度条颜色layer-list文件:layer-list创建的图形列表,也就是一个drawable 图形。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#FFFFD042" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="#f23f21" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#FF96E85D" />
</shape>
</clip>
</item> </layer-list>
整体xml布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LoginActivity"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="当前进度值:30"
android:id="@+id/textview"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekbar"
android:progress="30"
android:secondaryProgress="50"
android:maxHeight="5dp"
android:minHeight="5dp"
android:progressDrawable="@drawable/sb_bar"
android:thumb="@drawable/sb_thumb"/> </LinearLayout>
Java文件三种状态事件的触发:
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Set up the login form.
SeekBar seekBar = (SeekBar)findViewById(R.id.seekbar);
final TextView textView = (TextView)findViewById(R.id.textview);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override//进度发生改变
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
textView.setText("当前进度值:"+i);
}
@Override//按下
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(LoginActivity.this,"按下",Toast.LENGTH_SHORT).show();
}
@Override//放开
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(LoginActivity.this,"放开",Toast.LENGTH_SHORT).show();
}
});
}
}
Android基础控件SeekBar拖动条的使用的更多相关文章
- Android基础控件ProgressBar进度条的使用
1.简介 ProgressBar继承与View类,直接子类有AbsSeekBar和ContentLoadingProgressBar, 其中AbsSeekBar的子类有SeekBar和RatingBa ...
- Android基础控件ListView基础操作
1.简介 基于Android基础控件ListView和自定义BaseAdapter适配器情况下,对ListView的数据删除和添加操作: public boolean add(E e) {//添加数据 ...
- android 基础控件(EditView、SeekBar等)的属性及使用方法
android提供了大量的UI控件,本文将介绍TextView.ImageView.Button.EditView.ProgressBar.SeekBar.ScrollView.WebView ...
- android基础控件的使用
控件在屏幕上位置的确定 通常情况下控件在屏幕上确定至少要连接两条线(一条水平,一条垂直) 如下图连接了四条线 辅助线 辅助线的调出: 水平辅助线:进入activity.xml的设计模式之后如下图 为了 ...
- 矩阵, 矩阵 , Android基础控件之ImageView
天下文章大家抄,以下所有内容,有来自copy,有来自查询,亦有自己的总结(目的是总结出自己的东西),所以说原创,不合适,说是转载也不恰当,所以我称之为笔记,可惜没有此分类选项,姑且不要脸一点,选择为原 ...
- android 基础控件 EditText
EditText 简介: EditText 控件继承 TextView ,它有TextView的所有属性和方法,并且自身是可编辑的: extends TextView java.lang.Object ...
- Android 基础控件 TextView
一TextView介绍: TextView是UI最基本的组件,使用TextView可以显示丰富的文本信息.设置添加TextView最常见的方法就是在xml中添加TextView元素,并指定属性.Tex ...
- Android基础控件TextClock和Chronometer的使用
1.简介 DigitalClock, TextClock,AnalogClock,Chronometer其中DigitalClock和AnalogClock废弃了! TextClock是在Androi ...
- Android基础控件单选按钮RadioButton和Checkbox复选按钮的使用
1.相关简介 RadioButton需要和RadioGroup结合使用,在RadioGroup设置布局方式! Checkbox是单独使用,本文为了方便放在了RadioGroup中! 2.简单使用 方法 ...
随机推荐
- linux下使用自带mail发送邮件
linux下使用自带mail发送邮件 mailx工具说明: linux可以通过安装mailx工具,mailx是一个小型的邮件发送程序,一般可以通过该程序在linux系统上,进行监控linux系统状态并 ...
- C++列表初始化是初始化本类自身含有的成员变量,不能直接初始化继承过来的成员变量
在构造函数体内赋值就是对的了
- 《parsing techniques》中文翻译和正则引擎解析技术入门
http://parsing-techniques.duguying.net/ (中文版) https://swtch.com/~rsc/regexp/ https://blog.csdn.net/m ...
- Java Collection - ArrayList & LinkedList
总结 ref: https://blog.csdn.net/qq_32679815/article/details/78907437 1-ArrayList是实现了基于动态数组的数据结构,Linked ...
- 关于DB9一些信号的缩写
https://www.cnblogs.com/CCJVL/archive/2010/02/04/1663565.html 场景:PCB板子与PC通过RS232连接,以下信号的方向相对于PCB板子而言 ...
- CSS-基本语法/引用/文本设置/选择器/css3属性
CSS-基本语法/引用/文本设置 css基本语法及页面引用 css基本语法 css的定义方法是: 选择器 { 属性:值; 属性:值; 属性:值;} 选择器是将样式和页面元素关联起来的名称,属性是希望设 ...
- prometheus配置详情
https://prometheus.io/docs/prometheus/latest/configuration/configuration/ 下面监控宿主机和容器的内存,CPU,磁盘等状态 gr ...
- Git中.gitignore忽略规则
# 此为注释 – 将被 Git 忽略 *.a # 忽略所有 .a 结尾的文件 !lib.a # 但 lib.a 除外 /TODO # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TO ...
- linux下phpstudy安装
linux下phpstudy安装 一.总结 一句话总结: 就是下载然后一步步用指令安装即可 二.linux下phpstudy安装 参考:linux下phpstudy安装https://www.cnbl ...
- day22_1-课前上节复习+os模块
# ********************day22_1-课前上节复习+os模块 *******************# ********************day22_1-课前上节复习+os ...