android-process-button,扁平化带进度显示的按钮,来自Google的开发专家dmytrodanylyk的作品。
显示效果如图所示。
项目地址:
https://github.com/dmytrodanylyk/android-process-button
二、源码分析
(1).类的概要
1. FlatButton,继承自Button。处理按钮的基本样式,包括背景,圆角和文字。
2. ProcessButton,继承自FlatButton。处理进度相关的显示,包括进度条样式、与进度相关的文字,并提供drawProgress()抽象方法由子类去实现。
3.剩下的三个类, ActionProcessButton, SubmitProcessButton, GenerateProcessButton,都继承自ProcessButton。各自实现了drawProgress()方法,绘制不同样式的进度条。
显示效果如图所示。
项目地址:
https://github.com/dmytrodanylyk/android-process-button
其中包含项目源码和Demo。
一、项目使用
(1).项目的引用
dependencies {
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.0'
}
(2).自定义属性的介绍
<resources>
<declare-styleable name="ProcessButton">
<!-- “加载中”显示的文字 -->
<attr name="pb_textProgress" format="string" />
<!-- “加载完成”显示的文字 -->
<attr name="pb_textComplete" format="string" />
<!-- “加载出错”显示的文字 -->
<attr name="pb_textError" format="string" />
<!-- “加载中”进度条背景 -->
<attr name="pb_colorProgress" format="color" />
<!-- “加载完成”进度条背景 -->
<attr name="pb_colorComplete" format="color" />
<!-- “加载出错”进度条背景 -->
<attr name="pb_colorError" format="color" />
</declare-styleable>
<declare-styleable name="FlatButton">
<!-- 按钮按下后的背景色 -->
<attr name="pb_colorPressed" format="color" />
<!-- 按钮默认的背景色 -->
<attr name="pb_colorNormal" format="color" />
<!-- 按钮的圆角半径 -->
<attr name="pb_cornerRadius" format="dimension" />
</declare-styleable>
</resources>
二、源码分析
(1).类的概要
1. FlatButton,继承自Button。处理按钮的基本样式,包括背景,圆角和文字。
2. ProcessButton,继承自FlatButton。处理进度相关的显示,包括进度条样式、与进度相关的文字,并提供drawProgress()抽象方法由子类去实现。
3.剩下的三个类, ActionProcessButton, SubmitProcessButton, GenerateProcessButton,都继承自ProcessButton。各自实现了drawProgress()方法,绘制不同样式的进度条。
类的继承图: