如何自定义控件
1: 自定义属性的声明与获取,建attrs文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="HorizontalProgressbarWithProgress">
<attr name="progress_unreach_color" format="color" />
<attr name="progress_unreach_height" format="dimension" />
<attr name="progress_reach_color" format="color" />
<attr name="progress_reach_height" format="dimension" />
<attr name="progress_text_color" format="color" />
<attr name="progress_text_size" format="dimension" />
<attr name="progress_text_offset" format="dimension" />
</declare-styleable>
</resources>
在main-java-包下边建立HorizontalProgressbarWithProgress.java文件
并继承ProgressBar,重写方法
public class HorizontalProgressbarWithProgress extends ProgressBar{
}
通过getContext().obtainStyledAttributes获取自定义属性,存放至TypedArray
TypedArray ta=getContext(