一个通用的顶部导航栏布局

简介:

在Android开发中,一个activity界面通常都会有一个顶部导航栏,有的是,左边一个返回按钮,中间一个标题,有的,右边还要几个文字,或者一个图标,更有甚者,左边有一个返回图标加几个文字,这种设计在android屡见不鲜,为了减少重复代码,我特别封装了一个控件commontopbar

github地址:https://github.com/wypeng2012/commontopbar

本人blog文章地址:点我

欢迎star和提出问题

效果图如下:

使用方式:

  1. 在xml里面使用
    
    <party.loveit.commontopbar.CommonTopBar
             android:id="@+id/common"
             android:layout_width="match_parent"
             android:layout_height="48dp"
             android:background="@color/top_bar_bg_color"/>
    
    
  2. 你的activity实现一个接口

public interface CommonTopBarClick {
          void onClickLeft();//click left view on CommonTopBar
          void onClickRight();//click right view on CommonTopBar
   }

  1. 设置监听

 mCommonTopBar = (CommonTopBar) findViewById(R.id.common);
  mCommonTopBar.setCommonTopBarClick(this);//of course you can not set it

  1. 显示或者隐藏view

 mCommonTopBar.isShowLeftView(true);
 mCommonTopBar.isShowRightView(true);

  1. 设置文字

setLeftText(CharSequence charSequence) //set left view text
 setLeftText(int textRes) //set left view text
  
 setMidText(CharSequence charSequence) //set mid view text
 setMidText(int textRes) //set mid view text
  
 setRightText(CharSequence charSequence) //set right view text
 setRightText(int textRes) //set right view text

  1. 设置图片

 setLeftImage(android.graphics.drawable.Drawable drawable) //set left image
 setLeftImage(int drawableRes) //set left image
  
 setRightImage(android.graphics.drawable.Drawable drawable) //set right image
 setRightImage(int drawableRes) //set right image

  1. 设置文字大小

 setLeftTextSize(float size) //set left text size
     
 setMidTextSize(float size) //set mid text size
     
 setRightTextSize(float size) //set right text size
  

  1. 设置文字颜色

 setLeftTextColor(android.content.res.ColorStateList colorStateList) //set left text color
 setLeftTextColor(int color) //set left text color
  
 setMidTextColor(android.content.res.ColorStateList colorStateList) //set mid text color
  setMidTextColor(int color) //set mid text color
  
 setRightText(int textRes) //set right view text
 setRightTextColor(android.content.res.ColorStateList colorStateList) //set right text color
  

  1. 添加margin

 addLeftMargin(float marginLeft) //set left view margin left,the param is dp
 addRightMargin(float marginRight) //set right view margin right,the param is dp

  1. 设置中间title的字数长度

setMidTextMaxLenth(int lenth) //set middle text max length

  1. 设置左边文字左边的图标

setLefTextViewDrawPadding(int size)//set DrawPadding
setLeftTextViewDrawLeft(@DrawableRes int drawableRes)//set left drawImg
setLeftTextViewDrawLeft(@NonNull Drawable drawableRes)//set left drawImg

如何远程依赖:

  1. Maven

<dependency>
  <groupId>party.loveit</groupId>
  <artifactId>commontopbarlibrary</artifactId>
  <version>1.0.5</version>
  <type>pom</type>
</dependency>

  1. Gradle
compile 'party.loveit:commontopbarlibrary:1.0.5'

  1. Ivy

<dependency org='party.loveit' name='commontopbarlibrary' rev='1.0.5'>
  <artifact name='$AID' ext='pom'></artifact>
</dependency>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值