TopMenuBar顶部通用菜单栏

TopMenuBar顶部通用菜单栏

TopMenuBar顶部通用菜单栏

Android 自定义组合控件实例,顶部通用菜单栏使用kotlin编写,你可以java代码调用也可以使用kotlin调用,自定义化程度高,控件整体分为三部分,左边按钮,中间按钮,右边按钮,分别都可以设置只显示文字还是图片,文字的颜色,字体大小,字体加粗,设置图片,图片大小,按钮距离左右间距,设置控件整体背景颜色和控件高度

控件截图

图为xml直接引用TopMenuBar控件的默认效果

MZBannerView 有以下功能

在xml中直接引用属性:

  1. 设置整体控件高度 topMenuHeight;
  2. 设置整体控件背景 topMenuBackground;
  3. 左边按钮设置,按钮类型:image-图片 text -文字 topMenuLeftType;
  4. 左边按钮设置,按钮左边距 topMenuMarginLeft;
  5. 左边按钮设置,按钮图片 topMenuLeftImage;
  6. 中间按钮设置,文字大小 topMenuCenterTextSize;
  7. 中间按钮设置,文字-粗体 normal-默认 bold-加粗 topMenuCenterTextStyle;
  8. 右边按钮设置,按钮类型: image-图片 text-文字 topMenuRightType;
  9. 右边按钮设置,按钮右边距 topMenuMarginRight;
  10. 右边按钮设置,按钮图片 topMenuRightImage;

自定义属性 attrs.xml

<resources>
    <declare-styleable name="TopMenuBarView">
        <!--整体控件-->
        <!--控件高度-->
        <attr name="topMenuHeight" format="dimension" />
        <!--控件背景-->
        <attr name="topMenuBackground" format="reference|color" />
        <!--左边按钮-->
        <!--按钮类型 image图片 text 文字-->
        <attr name="topMenuLeftType" format="enum">
            <enum name="image" value="0" />
            <enum name="text" value="1" />
        </attr>
        <!--按钮左边距-->
        <attr name="topMenuMarginLeft" format="dimension" />
        <!--按钮图片-->
        <attr name="topMenuLeftImage" format="reference|color" />

        <!--中间按钮-->
        <!--文字大小-->
        <attr name="topMenuCenterTextSize" format="dimension" />
        <!--文字-粗体 normal默认 bold加粗-->
        <attr name="topMenuCenterTextStyle" format="enum">
            <enum name="normal" value="0" />
            <enum name="bold" value="1" />
        </attr>

        <!--右边按钮-->
        <!--按钮类型 image图片 text 文字-->
        <attr name="topMenuRightType" format="enum">
            <enum name="image" value="0" />
            <enum name="text" value="1" />
        </attr>
        <!--按钮右边距-->
        <attr name="topMenuMarginRight" format="dimension" />
        <!--按钮图片-->
        <attr name="topMenuRightImage" format="reference|color" />
    </declare-styleable>
</resources>

使用方法

添加依赖

build.gradle

maven

add的build.gradle

implementation 'com.gitee.renchunlin:topMenuBar:v1.1'

布局中引用

<com.renchunlin.topmenubarview.TopMenuBarView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

项目地址

https://gitee.com/renchunlin/topMenuBar

源码下载,需要积分,内容跟上面gitee源码一样

下载地址:topMenuBar

posted @ 2021-05-14 14:54  我不是乘树猿  阅读(125)  评论(0编辑  收藏  举报