开发前期,titlebar demo案例
实现步骤
1在values下新建attrs.xml定义组件属性
<declare-styleable name="TitleBar">
<attr name="backgroundColor" format="color"/>
<attr name="titleText" format="string"/>
<attr name="titleTextSize" format="dimension"/>
<attr name="titleTextColor" format="color"/>
<attr name="leftText" format="string"/>
<attr name="leftBackground" format="dimension"/>
<attr name="leftTextSize" format="dimension"/>
<attr name="marginLeft" format="dimension"/>
<attr name="leftIsVisibility" format="boolean"/>
<attr name="rightText" format="string"/>
<attr name="rightBackground" format="dimension"/>
<attr name="rightTextSize" format="dimension"/>
<attr name="rightTextColor" format="color"/>
<attr name="marginRight" format="dimension"/>
<attr name="rightIsVisibility" format="boolean"/>
</declare-styleable>
2.组装布局
public class TitleBar extends RelativeLayout {private int backgroundColor; //默认背景
private Button lButton,rButton;//左右按钮
private TextView textView;//title
private float lTextSize;//左边按钮文字大小
private int lBackground;//左按钮背景
private String lText;//左按钮文字
private float rTextSize; //右按钮文字大小
private int rBackground;//右按钮背景
private String rText;//右按钮文字