Android 常用控件自定义样式RadioButton、CheckBox、ProgressBar、
一、RadioButton / CheckBox
系统自带的RadioButton/CheckBox的样式,注定满足不了实际运用中的情况,有时候自定义自己的样式;此次把自己中工作学习过程中所学到的东西总结如下:
先看效果图:
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:drawableRight="@drawable/rb_background"
android:text="AAA" /> <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:checked="true"
android:drawableRight="@drawable/rb_background"
android:text="BBB" />
rb_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg2" android:state_checked="true" android:state_enabled="true"></item>
<item android:drawable="@drawable/bg1" android:state_checked="false"></item>
</selector>
都比较简单,换作CheckBox也是一样的道理,不再举例;
另:在使用RadioGroup的时候,居然突然想不起来怎么获取当选前择的是哪一项,经过查证,通过RadioGroup.OnCheckedChangeListener接口即可获取选择项改变事件回调捕获选项id;
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
}
});
二、ProgressBar
1、使用图片实现滚动效果.原始图像
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/image_progress"
android:pivotX="50%"
android:pivotY="50%" > </rotate>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/my_progress" />
2、自定义ProgressBar颜色
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" > <shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<gradient
android:centerColor="#FFFFFF"
android:centerY="0.50"
android:endColor="#FFFF00"
android:startColor="#000000"
android:type="sweep" //
android:useLevel="false" />
</shape> </rotate>
3、自定义horizontal进度条
自定义ProgressBar横向样式进度条需要配置一个layer-list,其中包括3个item分别是background,secondaryProgress,progress分别用于表示ProgressBar的背景,次要进度(如:表示播放器缓冲的进度),进度的样式;
<?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>
<corners android:radius="5dip" /> <gradient
android:angle="270"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:startColor="#ff9d9e9d" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" /> <gradient
android:angle="270"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:startColor="#80ffd300" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" /> <gradient
android:angle="270"
android:endColor="#AEEEEE"
android:startColor="#FF3030" />
</shape>
</clip>
</item> </layer-list>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="10dip"
android:progress="20"
android:max="100"
android:progressDrawable="@drawable/pb_background"/>
未完待续...
Android 常用控件自定义样式RadioButton、CheckBox、ProgressBar、的更多相关文章
- [转]easyui常用控件及样式API中文收藏
[转]easyui常用控件及样式收藏 2013-05-06 23:01 30612人阅读 评论(0) 收藏 举报 分类: java ee(5) 目录(?)[+] CSS类定义: div easyu ...
- android 控件自定义样式
一.按钮(Button) 方式1.存在.9图片或图片时 可在drawable文件夹下新建xml文件style_button_one.xml,代码如下 <?xml version=" ...
- 常用的基本控件 android常用控件
1.TextView:(文本框):不能编辑 android:textColor="@color/tv_show_color" 字体颜色 android:textSize ...
- Android常用控件及对应Robotium API
最近发现Android控件不熟悉,看Robotium的API都费劲. 常用Android控件: 控件类型 描述 相关类 Button 按钮,可以被用户按下或点击,以执行⼀个动作 Button Text ...
- WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 日历控 ...
- Android中的常用控件之进度条(ProgressBar)
ProgressBar的常用属性:style,进度条的样式,默认为圆形,用style="?android:attr/progressBarStyleHorizontal"可以将进度 ...
- silverlight 控件自定义样式 实现方法
1:在app.xaml中加入需实现的样式,如: <Application.Resources> <Style x:Key="NodeStyle" TargetTy ...
- Android常用控件之GridView使用BaseAdapter
我们可以为GridView添加自定义的Adapter,首先看下用自定义Adapter的显示效果 在布局文件main.xml文件中定义一个GridView控件 <RelativeLayout xm ...
- 【转】WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要内容: 日历控件Calendar自定义样式: 日期控件DatePicker自定 ...
随机推荐
- 离线安装Sharepoint工具
1. 首先安装操作系统,Windows Server 2008 R2,可以是企业版,也可以是数据中心版.然后再安装上SP1. 2. 在"服务管理"里面,添加角色,安装IIS. ...
- Java集合学习--集合总结
一.ArrayList与Vector ArrayList与Vector很多地方大同小异,Vector现在已经基本不再使用.具体的管理如下:1.ArrayList与Vector都实现了List接口,底层 ...
- 百度翻译api 实现简易微信翻译小程序
介绍 口袋翻译 口袋翻译 微信小程序 翻译功能 含7类语言的相互翻译 包含最近10条的翻译历史回溯功能 微信搜索:简e翻译 功能展示 使用百度翻译api需要申请 appid 与 key 并在 ap ...
- Windows环境下使用kafka单机模式
测试运行环境 Win10 kafka_2.11-1.0.0 zookeeper-3.4.10 1.安装Zookeeper Kafka的运行依赖于Zookeeper,所以在运行Kafka之前我们需要安装 ...
- Sharepoint 2013与Sharepoint 2016的功能对比
开发人员功能 SharePoint Foundation 2013 SharePoint Server 2013 Standard CAL SharePoint Server 2013 Enterpr ...
- 浅谈PCA
最近在回顾PCA方面的知识,发现对于之前的很多东西有了新的理解,下面和大家分享下我的一些个人的理解 1.我们为什么要用PCA,它能解决我什么问题? PCA(Principal Component An ...
- POJ 2455 Secret Milking Machine(最大流+二分)
Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...
- 一个改变this指向bind的函数,vue源代码
function bind(fn, ctx) { return function (a) { var l = arguments.length; return l ? l > 1 ? fn.ap ...
- 自测之Lesson9:时钟与信号
题目一:编写一个获取当前时间的程序,并将其以“year-mon-day time”的形式输出. 程序代码: #include <stdio.h> #include <time.h&g ...
- 【IdentityServer4文档】- 打包和构建
打包和构建 IdentityServer 由多个 nuget 软件包组成的. IdentityServer4 nuget | github 包含 IdentityServer 核心对象模型,服务和中间 ...