自定义标签 titlebar

本文介绍了如何在Android开发中自定义TitleBar组件,详细步骤包括在attrs.xml中定义组件属性,组装布局,并在XML中引用及设置属性,提供了一种自定义样式和功能的titlebar解决方案。
摘要由CSDN通过智能技术生成

开发前期,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;//右按钮文字
 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值