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.简单使用 方法 ...
随机推荐
- python 在机器学习中应用函数
浅述python中argsort()函数的用法 (1).先定义一个array数据 1 import numpy as np 2 x=np.array([1,4,3,-1,6,9]) (2).现在我们可 ...
- 12-FileZilla-响应:550 Permission denied
window系统安装FileZilla与虚拟机上的Ubuntu传输文件: 状态:连接正常 问题:传输文件失败 报错:550 Permission denied 解决方法: 这是由于ftp服务器配置的问 ...
- 查看Linux 内核版本命令
1.Ubuntu 查看版本命令,三种方法. 1.使用 "uname -a" 2.使用 "lsb_release -a" 3.使用 "cat ...
- SQLserver执行命令
方法一:xp_cmdshell exec master..xp_cmdshell "whoami"默认执行是关闭 EXEC sp_configure 'show advanced ...
- C# 调用java的Webservice时关于非string类型处理
比如webservice地址是:http://wdft.com:80/services/getOrderService1.0?wsdl 方法是:getOrder 1.首先添加引用: 2. 3.引用完成 ...
- struts2类型转换2
如何自定义类型转换器 ? 1). 为什么需要自定义的类型转换器 ? 因为 Struts 不能自动完成 字符串 到 引用类型 的 转换. 2). 如何定义类型转换器: I. 开发类型转换器的类: 扩展 ...
- windows下 Mysql 8.0.x 数据库简单的导出和导入!!!
1.首先需要进入到mysql安装目录下的bin目录,执行cmd进入命令窗口. 2.导出(导出某个数据库,也可以针对某张表导出)2.1导出数据结构以及数据的命令: mysqldump -u root - ...
- SpringBoot防止重复请求,重复表单提交超级简单的注解实现
1. 注解接口 /** * @description 防止表单重复提交注解 */@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHO ...
- https://vjudge.net/contest/321565#problem/C 超时代码
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...
- Batch pk Shell - WindowsBatch与LinuxShell比较 [变量符号和关键字]
原文地址:WindowsBatch与LinuxShell比较[变量符号和关键字] 一 简单实例1)batch file @echo off rem output helloworld :: outp ...