Android-UI控件-SeekBar

本文介绍了Android中SeekBar控件的使用,包括如何设置样式、监听事件,并展示了通过SeekBar实现音量调节的实例,详细讲解了xml绘制自定义滑块和进度条的方法。
摘要由CSDN通过智能技术生成

拖动条控件SeekBar

SeekBar:允许用户拖动滑块来改变值,因此拖动条通过用

于对系统的某种数值进行调节

Android:thumb 指定一个Drawable对象,该对象将作为自

定义滑块

SeekBar的常见属性

style="@android:style/Widget.SeekBar" 指定seekbar

的样式

android:max=“200” 指定seekbar的最大值为200,默认是

100

android:progress="75"指定seekbar的当前值为75
android:thumb 设置seekbar的滑动块样式
android:progressDrawable 设置seekbar的进度条的样式

其中指定seekbar的当前值,我们也可以通过代码设置,

如:seekBar.setProgress(75);

SeekBar的简单使用与事件监听
1.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

xmlns:android="http://schemas.android.com/apk/res/

android"

xmlns:app="http://schemas.android.com/apk/res-

auto"
xmlns:tools=“http://schemas.android.com/tools
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:fitsSystemWindows=“true”

tools:context=“com.example.seekbarui.MainActivity”

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width=“match_parent”
android:layout_height="?

attr/actionBarSize"
android:background="?

attr/colorPrimary"

app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButto

n
android:id="@+id/fab"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“bottom|end”
android:layout_margin="@dimen/fab_margin"

android:src="@android:drawable/ic_dialog_map" />

</android.support.design.widget.CoordinatorLayout>

2.content_main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/

android"

xmlns:app="http://schemas.android.com/apk/res-

auto"
xmlns:tools=“http://schemas.android.com/tools
android:layout_width=“match_parent”
android:layout_height=“match_parent”

android:paddingBottom="@dimen/activity_vertical_ma

rgin"

android:paddingLeft="@dimen/activity_horizontal_ma

rgin"

android:paddingRight="@dimen/acti

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值