Android常用控件集合

2,018 阅读20分钟

在common库中,封装了大家常用的控件,有部分控件直接使用部分大佬的,网络请求使用wanandroid开放api,在此感谢诸位大佬!感谢开源!如果用得上记得点赞收藏! Github地址先献上一波!

非嵌套滑动加载

NestedScroll嵌套滑动刷新加载

懒加载

使用StatusManager

Banner

自定义ToolBar

自定义Menu

聊天气泡

自定义View集合1

自定义View集合2

自定义View集合3

自定义View集合4

依赖步骤:

第一步:

	allprojects {
		repositories {
			// 加入 jitpack
			maven { url 'https://jitpack.io' }
		}
	}

第二步:

	dependencies {
	        implementation 'com.github.Jooyer.Basics:common:1.0.9'
	}

v1.0.1变化:

1.非嵌套刷新控件上拉时会超过限定值, 非嵌套刷新控件先上拉不松手下滑无效 2.嵌套刷新控件上拉没有到达加载高度时松手会里面恢复没有平滑效果 3.LeftImgAndRightTextView属性进行调整 4.TopImgAndBottomTextView属性进行调整 5.其他控件文字大小属性调整

v1.0.2变化:

1.CustomSearchView增加光标是否显示属性 2.CustomSearchView增加设置cursorDrawable 3.CustomToolbar增加底部分割线为阴影同时保留设置为线,(阴影高度为5dp,会挤压标题等显示) 4.CustomToolbar增加设置阴影颜色 5.CustomToolbar增加设置背景颜色(ct_background_color),Shadow模式下有效,反之直接用系统android:background即可

v1.0.3变化:

  1. 对CustomSearchView的cursorDrawable适配9.0
  2. 完善多视图StatusManager控件

v1.0.4变化:

  1. 紧急修复由于StatusManager中将 CustomToolbar 或者 自定义的Toolbar 等实现 StatusProvider 接口的控件,移除原有的父容器,添加到RootStatusLayout容器中,导致UI界面无法使 CustomToolbar 或者 自定义的Toolbar 等实现 StatusProvider 接口的控件.

    ... 省略部分 ...
    
    	                val childParent = child.parent as ViewGroup
                    // 移除掉原来的,则会导致界面错位,添加一个占位的,但是占位视图设置为 View.INVISIBLE(不可见的)
                    childParent.removeView(child)
                    // 占位View
                    val view = View(context)
                    view.setBackgroundColor(Color.TRANSPARENT)
                    // 保证原来的ID不变,是防止其他控件对此控件有依赖或者位置关系
                    view.id = child.id
                    view.visibility = View.INVISIBLE
                    childParent.addView(view, 0, params)
                    child.id = R.id.ct_tool_bar
                    addView(child, params)
    
    ... 省略部分 ...
    PS: 具体源码请参考: cn.lvsong.lib.library.state.RootStatusLayout.getCustomToolbar(viewGroup: ViewGroup)
    

v1.0.5变化:

  1. 对CustomMenu添加设置底部分割线高度
  2. 对CustomMenu添加设右侧箭头线宽
  3. 修复StatusManager如果使用contentView(contentLayoutView: View) 因其内部未初始化造成异常

v1.0.6变化:

  1. 增加折叠控件ExpandableTextView
  2. 对CustomToolbar增加动态设置字体颜色
  3. 修复其他bug

v1.0.7变化:

  1. 对ExpandableTextView增加属性
  2. 对CustomSearchView右侧清除文本图标增加必要属性和方法

v1.0.8变化:

  1. 对banner增加缩放效果(Gallery)
  2. 对banner在列表中显示异常处理
  3. 对NestedRefreshLayout属性进行调整,使其易读易懂
  4. 部分其他控件自定义属性增加必要注释

v1.0.9变化:

  1. StatusManager设置LoadingView背景色时异常
  2. 对ImageLoader增加高斯模糊
  3. 添加Glide在 placeHolder 时圆角占位图处理方案

[toc]

ArcView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity1

        <cn.lvsong.lib.library.view.ArcView
        android:id="@+id/btn_5"
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_200"
        android:layout_margin="@dimen/padding_5"
        app:av_arc_control_offset="@dimen/padding_20"
        app:av_arc_offset="@dimen/padding_20"
        app:av_background_color="@color/color_2878FF" />

属性介绍:

属性名称取值类型取值和作用
av_arc_offsetfloat|dimension曲线与直线交点处 相对于图形高度的偏移量,默认0
av_background_colorreference|color背景色
av_arc_control_offsetfloat|dimension曲线控制点相对于控件高度偏移量,默认0

==PS: 如果设置控件高度为200dp, av_arc_offset = 20dp,则相当于矩形部分高度是180dp, av_arc_control_offset取值<=av_arc_offset,也就是如果想弧度更大,则av_arc_offset取值更大==

公共方法:

暂无!

ArrangeView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity1

步骤一:

    <cn.lvsong.lib.library.view.ArrangeView
        android:id="@+id/av"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/height_40"
        android:layout_marginStart="@dimen/padding_10"
        android:layout_marginTop="@dimen/padding_10"
        app:av_first_show_top="false"
        app:av_show_count="6"
        app:av_space_width="@dimen/padding_8"
        />

步骤二:

        val data = arrayListOf<String>(
            "https://upload.jianshu.io/users/upload_avatars/2631077/dc99c361412c?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240",
            "https://upload.jianshu.io/users/upload_avatars/1300228/1169f257-ab3b-44f2-bed2-57282511eb8f.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240",
            "https://upload.jianshu.io/users/upload_avatars/7133325/f4370cf6-cf4d-4839-9b54-87beaa767d48?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240",
            "https://upload.jianshu.io/users/upload_avatars/7290998/f64f5ef0-def0-4b26-beb3-b9d88f060ba0.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240",
            "https://upload.jianshu.io/users/upload_avatars/2558050/7761b285-2805-4534-9870-ba7dcc7538ec.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240"
        )
        av.setAdapter(object : ArrangeView.ArrangeAdapter(data) {
            override fun getRangeView(position: Int, parent: ViewGroup): View {
                val view = LayoutInflater.from(this@CustomActivity1)
                    .inflate(R.layout.item_arrange_view_peoples, parent, false)
                ImageLoad.loader.loadImgWithCircleAndRing(
                    view.findViewById(R.id.iv_range_view),
                    getItem(position),
                    2F,
                    Color.WHITE
                )
                return view
            }
        } )

属性介绍:

属性名称取值类型取值和作用
av_space_widthreference|dimension每一个Item重叠部分,默认20dp
av_show_countinteger一共显示多个ItemView,默认4个
av_first_show_topinteger是否开头的显示在最上方,默认不是

公共方法

方法名称作用
setAdapter(adapter: ArrangeAdapter)设置适配器

BackArrowView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity1

   <cn.lvsong.lib.library.view.BackArrowView
        android:id="@+id/bav"
        android:layout_width="@dimen/width_40"
        android:layout_height="@dimen/height_40"
        android:layout_marginTop="@dimen/padding_10"
        app:bav_arrow_style="material_design"
        app:bav_arrow_color="@color/color_2878FF"
        app:bav_stroke_width="1.5dp"
        />

属性介绍:

属性名称取值类型取值和作用
bav_arrow_colorcolor箭头颜色,默认#666666
bav_stroke_widthinteger|dimension箭头线宽,默认2dp
bav_arrow_paddingdimension|integerpadding 使得里面 × 变小,默认1dp
bav_arrow_styleenum箭头模式, material_design(Material Design),默认值; wechat_design(微信风格)

公共方法:

方法名称作用
setArrowColor(int arrowColor)设置箭头颜色
setArrowStyle(int arrowStyle)设置箭头模式
setArrowPadding(float padding)设置内边距

BadgeView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity2

    <cn.lvsong.lib.library.view.BadgeView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/padding_5"
        app:bv_number="111"
        app:bv_text_size="@dimen/text_size_14"
        app:bv_stoke_width="1.5dp"
        app:bv_more_style="plus"
        app:bv_text_medium="false"
        app:bv_background_color="@color/color_2878FF"
        app:bv_lr_padding="@dimen/padding_8"
        app:bv_tb_padding="@dimen/padding_5"
        />

属性介绍:

属性名称取值类型取值和作用
bv_tb_paddingdimension|integer上下间隔,默认3dp,最小1dp
bv_lr_paddingdimension|integer左右间隔,默认5dp,最小1dp
bv_stoke_widthdimension|float轮廓宽度,默认1dp,
bv_stoke_colorcolor裸辞颜色,默认白色
bv_text_sizedimension|integer文字大小,默认14dp
bv_text_colorcolor文字颜色,默认白色
bv_text_mediumboolean文字中粗,默认是的
bv_background_colorcolor背景色,默认红色
bv_numberinteger显示数值
bv_more_styleenum显示风格,>99显示(dot)..., 或者显示(plus)+ ,默认显示...

公共方法:

方法名称作用
setNumber(number: Int)设置具体消息数量

Banner(RecyclerView实现)

用法:

具体参考: cn.lvsong.lib.demo.BannerActivity

步骤一: 在xml中引入

    <cn.lvsong.lib.library.banner.BannerLayout
        android:id="@+id/banner"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        app:banner_indicator_height="10dp"
        app:banner_indicator_margin="3dp"
        app:banner_normal_indicator_drawable="@drawable/normal"
        app:banner_select_indicator_drawable="@drawable/select"
        app:banner_loop_time="3000"
        app:banner_show_indicator="true"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

步骤二: 继承自BannerAdapter实现 adapter

class CustomAdapter(data: List<String>, layoutId: Int) :
    BannerAdapter<String>(data, layoutId) {
    override fun onBindViewHolder(holder: BannerHolder, position: Int) {
        holder.itemView.findViewById<AppCompatTextView>(R.id.tv_position).text = "$position"
        ImageLoad.loader.loadImage(holder.itemView.findViewById<AppCompatImageView>(R.id.iv_banner), mData[position])
    }

}

步骤三:

  banner.setBannerAdapter(adapter, DensityUtil.dp2pxRtInt(10)) // 第二参数表,每一个item间隔

属性介绍:

属性名称取值类型取值和作用
banner_indicator_heightreference|dimension指示器高度
banner_indicator_marginreference|dimension指示器内部 View 左右Margin
banner_show_indicatorboolean是否显示指示器
banner_loop_timeinteger轮播时间间隔,默认3000ms
banner_select_indicator_drawablereference指示器选中状态图片
banner_normal_indicator_drawablereference指示器默认状态图片
banner_item_scroll_timeintegerItemView 滑动时滑过一屏所需时间,默认1200

公共方法:

方法名称作用
fun setBannerAdapter( adapter: RecyclerView.Adapter, spaceWidth: Int = 0 )绑定banner适配器
onPause()暂停滑动
onResume()继续滑动
onStop()停止滑动
setOnPositionChangeListener(positionChangeListener: OnPositionChangeListener)如果需要知道当前显示的下标,可以通过此回调获取

BubbleLinearLayout

用法:

具体参考:

    <cn.lvsong.lib.library.bubble.BubbleLinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:bubbleColor="@color/color_B1B6D1"
        >

        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/iv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:layout_margin="@dimen/padding_10"
            />
        

    </cn.lvsong.lib.library.bubble.BubbleLinearLayout>

属性介绍:

属性名称取值类型取值和作用
bll_arrow_widthdimension|integer箭头宽度,默认25px
bll_anglefloat|dimension四周圆角每一个圆角角度,默认20°
bll_arrow_heightdimension|integer箭头高度,默认25px
bll_arrow_positiondimension|integer箭头位置,当arrowLocation确定时箭头初始位置的偏移量,,默认50px
bll_bubble_colorcolor气泡背景色
bll_arrow_centerboolean箭头居中,此时arrowPosition无效,默认false
bll_arrow_locationenum箭头方向,默认在左边 ,可取: left,right,top,bottom,top_right

公共方法:

方法名称作用
setArrowAngle(angle: Float)设置四周圆角每一个圆角角度
setArrowHeight(arrowHeight: Float)设置箭头高度
setArrowLocation(arrowLocation: BubbleDrawable.ArrowLocation)设置箭头方向
setArrowPosition(arrowPosition: Float)设置箭头位置
setArrowWidth(arrowWidth: Float)设置箭头宽度
setArrowCenter(arrowCenter: Boolean)设置箭头居中,此时arrowPosition无效,默认false
setBubbleColor(bubbleColor: Int)设置气泡背景色

ChrysanthemumView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity2

    <cn.lvsong.lib.library.refresh.ChrysanthemumView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/padding_20"
        android:layout_marginStart="@dimen/padding_20"
        app:chrysanthemum_view_color="@color/color_E95C5B5B"
        app:chrysanthemum_view_radius="@dimen/padding_15"
        app:chrysanthemum_view_width="@dimen/padding_8"
        app:chrysanthemum_view_height="@dimen/padding_3"
        app:chrysanthemum_flower_count="10"
        />

属性介绍:

属性名称取值类型取值和作用
cv_flower_countinteger花瓣的数量,一般去偶数 8,10,12
cv_view_radiusdimension|integer菊花半径
cv_view_widthdimension|integer每一片花瓣的长度
cv_view_heightdimension|integer每一片花瓣的厚度
cv_view_colorcolor花瓣的颜色

公共方法:

方法名称作用
start()开始旋转,如果控件可见就会自动执行,不必手动调用
stop()暂停旋转,如果控件不可见就会自动执行,不必手动调用

CloseView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity2

    <cn.lvsong.lib.library.view.CloseView
        android:id="@+id/cv2"
        android:layout_width="@dimen/width_40"
        android:layout_height="@dimen/height_40"
        android:layout_margin="@dimen/padding_5"
        app:cv_circle_line_color="@color/main_theme_color"
        app:cv_circle_line_width="2dp"
        app:cv_circle_has_bg="true"
        app:cv_circle_bg_padding="2dp"
        app:cv_circle_bg_color="@color/color_8A8EA3"
        app:cv_line_width="1.5dp"
        app:cv_mode="circle" />

属性介绍:

属性姓名取值类型取值和作用
cv_line_widthinteger|dimension叉叉的线高
cv_line_colorcolor叉叉的颜色
cv_line_paddinginteger|dimensionpadding 使得里面 × 变小
cv_modeenum模式,普通模式(normal)只有叉叉、圆边模式(circle)带圆形背景
cv_circle_line_colorcolor圆的轮廓线颜色
cv_circle_line_widthinteger|dimension圆的轮廓线宽,如果指定为0 ,则不绘制圆环
cv_circle_has_bgboolean是否绘制背景,默认不绘制,只有在 cv_mode = circle才有效,此时就不要再设置 android:background
cv_circle_bg_colorcolor背景色,只有在 cv_mode = circle才有效
cv_circle_bg_paddingdimension|integerpadding 使得在 cv_mode = circle 时,轮廓线往内变小,同时点击面积没有变小

公共方法:

方法名称作用
setColor(int color)设置叉叉的颜色,默认#444444
setLineWidth(float lineWidth)设置叉叉线的宽度(厚度),默认1.5dp
setLinePadding(float padding)使得里面 × 变小,这样不影响点击范围,默认4dp
setMode(int mode)设置控件是圆形(此时背景色和圆环才有效果)还是方形,默认方形(1)
setHasBg(boolean hasBg)设置控件是否拥有背景色,默认false
setBgColor(int bgColor)设置控件背景色.默认透明

CountDownView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity2

    <cn.lvsong.lib.library.view.CountDownView
        android:id="@+id/cdv"
        android:layout_width="@dimen/width_60"
        android:layout_height="@dimen/height_60"
        android:layout_margin="@dimen/padding_5"
        app:cdv_bg_color="@android:color/holo_red_dark"
        app:cdv_ring_color="@color/main_theme_color"
        app:cdv_ring_width="@dimen/padding_5"
        app:cdv_text_info="5s"
        />

属性介绍:

属性名称取值类型取值和作用
cdv_ring_colorcolor圆环颜色
cdv_ring_widthinteger|dimension圆环宽度
cdv_bg_colorcolor背景色
cdv_text_colorcolor文本颜色
cdv_text_sizeinteger|dimension文本大小
cdv_text_infostring|reference文本内容

公共方法:

方法名称作用
startCountDown(duration: Long)开始倒计时,注意单位为==秒==

CustomEditMenu

用法:

具体参考: cn.lvsong.lib.demo.CustomMenuActivity

      <cn.lvsong.lib.library.view.CustomEditMenu
            android:layout_width="match_parent"
            android:layout_height="@dimen/height_50"
            android:layout_marginTop="@dimen/padding_10"
            app:cem_bottom_divider_color="@color/color_8A8EA3"
            app:cem_bottom_divider_visible="true"
            app:cem_left_image_drawable="@drawable/ic_baseline_assignment_returned_24"
            app:cem_left_image_margin="@dimen/padding_10"
            app:cem_left_text_info="左侧图片右侧输入框+图片"
            app:cem_right_image_drawable="@drawable/ic_baseline_alarm_add_24"
            app:cem_right_image_right_margin="@dimen/padding_10"
            app:cem_right_input_hint_color="@color/color_B1B6D1"
            app:cem_right_input_hint_text="请输入昵称" />

属性介绍:

属性名称取值类型取值和作用
cem_left_image_visibleboolean最左侧图标是否可见
cem_left_image_drawablereference最左侧图标的 drawable
cem_left_image_widthdimension|integer最左侧图标宽度
cem_left_image_heightdimension|integer最左侧图标高度
cem_left_image_margindimension|integer最左侧图标leftMargin
cem_left_text_inforeference|string紧靠左侧的文本
cem_left_text_sizedimension|integer紧靠左侧的文本大小
cem_left_text_colorcolor|reference紧靠左侧的文本颜色
cem_left_text_left_margindimension|integer紧靠左侧的文本leftMargin
cem_right_input_visibleboolean右侧输入框的文本是否可见
cem_right_input_left_paddingdimension|integer右侧输入框leftPadding
cem_right_input_right_paddingdimension|integer右侧输入框rightPadding
cem_right_input_widthdimension|integer右侧输入框宽度
cem_right_input_textreference|string右侧输入框的文本,非提示文本
cem_right_input_hint_textreference|string右侧输入框的提示文本
cem_right_input_text_sizedimension|integer右侧输入框的文本大小
cem_right_input_text_lengthinteger右侧输入框的文本长度
cem_right_input_text_colorcolor|reference右侧输入框的文本颜色
cem_right_input_hint_colorcolor|reference右侧输入框的提示文本颜色
cem_right_input_right_margindimension|integer右侧输入框的文本rightMargin
cem_right_input_typeenum右侧输入框输入的类型,默认是文本, 如果输入number则表示数字
cem_right_image_visibleboolean最右侧图标的是否可见
cem_right_image_drawablereference最右侧图标的 drawable
cem_right_image_widthdimension|integer最右侧图标宽度
cem_right_image_heightdimension|integer最右侧图标高度
cem_right_image_right_margindimension|integer最右侧图标高度rightMargin
cem_bottom_divider_visibleboolean底部分割线是否可见
cem_bottom_divider_colorcolor|reference底部分割线颜色
cem_bottom_divider_left_margindimension|integer底部分割线leftMargin
cem_bottom_divider_right_margindimension|integer底部分割线rightMargin

公共方法:

方法名称作用
setLeftImageVisible(visible: Int)设置左侧图标是否可见
setLeftImageDrawable(drawable: Drawable)设置左侧图标
setLeftText(text: String?)设置左侧文本
setLeftText(text: String?,@ColorInt color: Int)设置左侧文本和字体颜色
setRightEditTextVisible(isVisible: Boolean)设置右侧输入框是否可见
setRightEditText(text: String?,@ColorInt color: Int)设置右侧输入框文本和颜色
setRightEditText(text: String?)设置右侧输入框文本
setRightEditHintText(text: String?,@ColorInt color: Int)设置右侧输入框提示文本和颜色
setRightEditHintText(text: String?)设置右侧输入框提示文本
setRightImageVisible(visible: Int)设置右侧图标是否可见
setRightImageDrawable(drawable: Drawable)设置右侧图标

CustomMenu

用法:

具体参考: cn.lvsong.lib.demo.CustomMenuActivity

        <cn.lvsong.lib.library.view.CustomMenu
            android:layout_width="match_parent"
            android:layout_height="@dimen/height_50"
            android:layout_marginTop="@dimen/padding_10"
            app:cm_bottom_divider_color="@color/color_2878FF"
            app:cm_bottom_divider_left_margin="@dimen/height_10"
            app:cm_bottom_divider_visible="true"
            app:cm_left_image_drawable="@drawable/ic_baseline_alarm_add_24"
            app:cm_left_image_margin="@dimen/padding_10"
            app:cm_left_text_color="@color/color_333333"
            app:cm_left_text_info="左侧图片右侧图片+小红点"
            app:cm_left_text_left_margin="@dimen/padding_5"
            app:cm_right_near_image_drawable="@drawable/select"
            app:cm_right_near_image_height="@dimen/height_10"
            app:cm_right_near_image_right_margin="@dimen/padding_2"
            app:cm_right_near_image_top_margin="@dimen/padding_12"
            app:cm_right_near_image_visible="true"
            app:cm_right_near_image_width="@dimen/width_10"
            app:cm_right_text_info="版本更新"
            app:cm_right_text_right_margin="@dimen/padding_2" />

属性介绍:

属性名称取值类型取值和作用
cm_left_image_visibleboolean最左侧图标是否可见
cm_left_image_drawablereference最左侧图标的 drawable
cm_left_image_widthdimension|integer最左侧图标宽度
cm_left_image_heightdimension|integer最左侧图标高度
cm_left_image_left_margindimension|integer最左侧图标LeftMargin
cm_left_text_inforeference|string紧靠左侧的文本
cm_left_text_sizedimension|integer紧靠左侧的文本大小
cm_left_text_colorcolor|reference紧靠左侧的文本颜色
cm_left_text_left_margindimension|integer紧靠左侧的文本LeftMargin
cm_right_text_visibleboolean紧靠右侧的文本是否可见
cm_right_text_inforeference|string紧靠右侧的文本
cm_right_text_sizedimension|integer紧靠右侧的文本大小
cm_right_text_colorcolor|reference紧靠右侧的文本颜色
cm_right_text_right_margindimension|integer紧靠右侧的文本RightMargin
cm_right_near_image_visibleboolean紧靠右侧图标是否可见
cm_right_near_image_drawablereference紧靠右侧图标的 drawable
cm_right_near_image_widthdimension|integer紧靠右侧图标宽度
cm_right_near_image_heightdimension|integer紧靠右侧图标高度
cm_right_near_image_right_margindimension|integer紧靠右侧图标rightMargin,距离最右侧
cm_right_near_image_top_margindimension|integer紧靠右侧图标顶部Margin,距离最上面,默认0dp
cm_right_arrow_visibleboolean最右侧箭头的是否可见
cm_right_arrow_colorcolor|reference"最右侧箭头的 颜色
cm_right_arrow_paddingdimension|integer最右侧箭头 Padding(上下左右),默认1dp
cm_right_arrow_orientationenum最右侧箭头方向, 向左(left)或向右(right),默认right
cm_right_arrow_styleenum最右侧箭头模式,material_design(Material Design),wechat_design(微信风格),默认material_design
cm_right_arrow_widthdimension|integer最右侧箭头宽度,方便点击区域
cm_right_arrow_heightdimension|integer最右侧箭头高度,方便点击区域
cm_right_arrow_strokedimension|float最右侧箭头线条宽度,默认2dp
cm_right_arrow_right_margindimension|integer最右侧箭头rightMargin
cm_bottom_divider_visibleboolean底部分割线是否可见
cm_bottom_divider_heightdimension|float底部分割线高度,默认1px
cm_bottom_divider_colorcolor|reference底部分割线颜色
cm_bottom_divider_left_margindimension|integer底部分割线leftMargin
cm_bottom_divider_right_margindimension|integer底部分割线rightMargin

公共方法:

方法名称作用
setRightTextVisible(isVisible: Boolean)右侧文本是否显示
setRightImageViewVisible(isVisible: Boolean)右侧图标是否显示
setLeftText(text: String?)设置左侧文本
setLeftText(text: String?, color: Int)设置左侧文本和颜色
setRightText(text: String?)设置右侧文本
setRightText(text: String?, color: Int)设置右侧文本和颜色
setLeftImage(@DrawableRes resource: Int)设置左侧图标
setRightImage(@DrawableRes resource: Int)设置右侧图标
setMoreViewListener(listener: View.OnClickListener)设置箭头点击事件

CustomSearchView

用法:

具体参考: cn.lvsong.lib.demo.CustomMenuActivity

                <cn.lvsong.lib.library.view.CustomSearchView
            android:id="@+id/csv_1"
            android:layout_width="match_parent"
            android:layout_height="@dimen/height_50"
            android:layout_marginTop="@dimen/padding_10"
            app:csv_input_container_drawable="@drawable/ic_gray_solid_rectangle_r5"
            app:csv_input_container_margin_right="@dimen/padding_10"
            app:csv_input_cursor_visible="true"
            app:csv_input_hint_text="请输入搜索内容"
            app:csv_search_btn_bg_color="@color/color_2878FF"
            app:csv_search_btn_text_bold="true"
            app:csv_search_btn_text_color="@color/color_FFFFFF"
            app:csv_search_btn_width="@dimen/width_40" />

属性介绍:

属性名称取值类型取值和作用
csv_left_arrow_visibleboolean是否显示返回按钮
csv_left_arrow_colorcolor|reference左侧箭头的颜色
csv_left_arrow_paddingdimension|integer左侧箭头 Padding(上下左右)
csv_left_arrow_styleenum左侧箭头模式,material_design(Material Design),wechat_design(微信风格),默认是material_design
csv_search_icon_showboolean是否显示搜索图标,默认显示
csv_search_icon_colorcolor|reference搜索图标颜色
csv_clear_icon_showboolean是否显示清除图标,默认显示
csv_clear_icon_colorcolor|reference清除图标颜色
csv_clear_icon_line_widthinteger|dimension清除图标线宽(厚度),默认1.5dp
csv_clear_icon_line_paddingdimension|integer使得里面 × 变小同时点击面积没有变小,默认0dp
csv_clear_icon_margin_rightdimension|integer清除图标rightMargin,默认6dp
csv_clear_icon_modeenum清除图标模式,普通模式normal(默认)、圆形模式circle
csv_clear_icon_circle_radiusinteger|dimension清除图标半径,只有在 cv_mode = circle才有效,且此时必须设置,否则图标较大,默认为10dp
csv_clear_icon_has_bgboolean是否绘制背景,默认不绘制,只有在 cv_mode = circle才有效,此时就不要再设置 android:background
csv_clear_icon_bg_colorcolor背景色,只有在 cv_mode = circle才有效,默认透明
csv_input_container_heightdimension|reference中间搜索容器高度,最小高度 30dp,默认36dp
csv_input_container_margin_leftdimension|reference中间搜索容器leftMargin
csv_input_container_margin_rightdimension|reference中间搜索容器rightMargin
csv_input_container_drawablereference中间搜索容器drawable,也就是容器的背景
csv_input_left_paddingdimension|float中间搜索输入框leftPadding
csv_default_search_textstring|reference默认的搜索文本
csv_input_text_sizedimension|float中间搜索输入框文本大小
csv_input_text_colorcolor|reference中间搜索输入框文本颜色
csv_input_hint_textstring|reference中间搜索输入框提示文本
csv_input_hint_colorcolor|reference中间搜索输入框提示文本颜色
csv_input_max_lengthinteger中间搜索输入框最大输入文本长度,默认不限制
csv_input_cursor_visibleboolean中间搜索输入框光标是否显示,默认显示
csv_input_cursor_drawablereference中间搜索输入框光标自定义drawable,不需要可以不设置,也可以设置一个自定义的drawable
csv_need_jumpboolean点击整个搜索控件,此时如果需要跳转,则设置为true
csv_search_btn_visibleboolean是否显示搜索按钮,默认显示
csv_search_btn_textstring|reference搜索按钮显示文本
csv_search_btn_text_sizedimension|float搜索按钮文本大小
csv_search_btn_text_colorcolor|reference搜索按钮文本颜色
csv_search_btn_text_boldboolean右侧文本是否加粗,类似苹果中黑效果,默认是true(加粗的)
csv_search_btn_bg_colorcolor|reference搜索按钮背景颜色
csv_search_btn_widthdimension|reference搜索按钮宽度
csv_search_btn_heightdimension|reference搜索按钮高度
csv_search_btn_margin_rightdimension|reference搜索按钮宽度rightMargin
csv_bottom_divider_visibleboolean底部分割线 ,默认隐藏
csv_bottom_divider_colorcolor|reference底部分割线颜色

公共方法:

方法名称作用
setOnSearchListener(listener: OnSearchListener)对各种操作的回调

CustomToolbar

用法:

具体参考: cn.lvsong.lib.demo.CustomToolbarActivity ,

PS: 一般右侧显示一个文本按钮(或者2个图标按钮,或者更多按钮),如果需要同时设置多个,发现重叠,有margin_right的属性,可以通过调节大小

    <cn.lvsong.lib.library.view.CustomToolbar
        android:id="@+id/ct_9"
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_50"
        app:ct_center_text_color="@color/color_333333"
        app:ct_center_text_info="将底部分割线style改为line"
        app:ct_center_text_size="@dimen/text_size_16"
        app:ct_left_arrow_color="@color/color_2878FF"
        app:ct_left_arrow_height="@dimen/height_50"
        app:ct_left_arrow_padding="@dimen/padding_3"
        app:ct_left_arrow_style="material_design"
        app:ct_left_arrow_width="@dimen/width_40"
        app:ct_right_image2_drawable="@drawable/ic_baseline_assignment_returned_24"
        app:ct_right_image2_right_margin="@dimen/padding_30"
        app:ct_right_image2_visible="true"
        app:ct_right_image2_width="@dimen/width_40"
        app:ct_right_mav_color="@color/color_666666"
        app:ct_right_mav_dot_radius="@dimen/padding_2"
        app:ct_right_mav_height="@dimen/height_50"
        app:ct_right_mav_orientation="vertical"
        app:ct_right_mav_right_margin="@dimen/padding_2"
        app:ct_right_mav_visible="true"
        app:ct_right_mav_width="@dimen/width_40"
        app:ct_bottom_divider_style="LINE"
        app:ct_bottom_divider_color="@color/color_666666"
        />

属性介绍:

属性名称取值类型取值和作用
ct_left_arrow_visibleboolean左侧箭头是否显示, 默认true
ct_left_arrow_widthdimension|integer左侧箭头宽度, 默认40dp
ct_left_arrow_heightdimension|integer左侧箭头高度, 默认50dp
ct_left_arrow_paddingdimension|integer左侧箭头 Padding(上下左右), 默认3dp
ct_left_arrow_left_margindimension|integer左侧箭头左侧 Margin, 默认0dp
ct_left_arrow_colorcolor|reference左侧箭头的颜色, 默认#999999
ct_left_arrow_styleenum左侧箭头模式, ,默认Material Design, material_design(Material Design),wechat_design(微信风格)
ct_left_text_visibleboolean左侧文本是否显示, 默认false
ct_left_text_inforeference|string左侧文本
ct_left_text_sizedimension左侧文本大小, 默认15dp
ct_left_text_colorcolor|reference左侧文本颜色, 默认#333333
ct_left_text_left_margindimension|integer左侧文本左侧 Margin, 默认25dp
ct_center_text_inforeference|string中间文本
ct_center_text_sizedimension中间文本大小, 默认18dp
ct_center_text_colorcolor|reference中间文本颜色,默认 #333333
ct_right_text_visibleboolean右侧文本是否可见, 默认false
ct_right_text_inforeference|string右侧文本
ct_right_text_sizedimension右侧文本大小, 默认15dp
ct_right_text_colorcolor|reference右侧文本颜色, 默认#333333
ct_right_text_right_margindimension|integer右侧文本右侧 Margin, 默认12dp
ct_right_text_boldboolean右侧文本是否加粗,类似苹果中黑效果,默认是加粗的
ct_right_image_visibleboolean右侧图片1是否可见,默认false
ct_right_image_checkedboolean右侧图片是否选中,默认false
ct_right_image_drawablereference右侧图片1 Drawable
ct_right_image_drawable_checkedreference右侧图片1 选中后Drawable
ct_right_image_widthdimension|integer右侧图片1宽度,默认22dp
ct_right_image_heightdimension|integer右侧图片1高度,默认22dp
ct_right_image_paddingdimension|integer右侧图片1 Padding(上下左右),默认0dp
ct_right_image_right_margindimension|integer右侧图片1右侧 rightMargin,默认5dp
ct_right_image2_visibleboolean右侧图片2是否可见,默认false
ct_right_image2_checkedboolean右侧图片2是否选中,默认false
ct_right_image2_drawablereference右侧图片2 Drawable
ct_right_image2_drawable_checkedreference右侧图片2 选中后Drawable
ct_right_image2_widthdimension|integer右侧图片2宽度,默认22dp
ct_right_image2_heightdimension|integer右侧图片2高度,默认22dp
ct_right_image2_paddingdimension|integer右侧图片2 Padding(上下左右),默认0dp
ct_right_image2_right_margindimension|integer右侧图片2右侧 rightMargin,默认10dp
ct_right_mav_visibleboolean右侧更多按钮是否可见,默认不可见,默认false
ct_right_mav_widthdimension|integer右侧更多按钮宽度,主要是设置点击范围, 默认40dp
ct_right_mav_heightdimension|integer右侧更多按钮高度,主要是设置点击范围, 默认40dp
ct_right_mav_right_margindimension|integer右侧更多按钮rightMargin,默认5dp
ct_right_mav_colorcolor|reference右侧更多按钮的颜色, 默认#2878FF
ct_right_mav_dot_radiusdimension|integer右侧更多按钮大小,圆点半径,默认2dp
ct_right_mav_orientationenum右侧更多按钮排列方向,水平或垂直, horizontal(水平),vertical(垂直), 默认垂直
ct_bottom_divider_visibleboolean底部分割线是否可见, 默认true
ct_bottom_divider_colorcolor|reference底部分割线颜色,如果分割线不可见(或者ct_bottom_divider_style = SHADOW)则此属性无效
ct_bottom_shadow_colorcolor|reference底部shadow颜色(推荐颜色值必须是8位,即有alpha),默认#26000000,如果分割线不可见(或者ct_bottom_divider_style = LINE)则此属性无效
ct_bottom_divider_styleenum底部分割线样式,SHADOW(阴影效果),默认值; LINE(分割线效果),如果分割线不可见则此属性无效
ct_background_colorcolor|reference背景色,默认白色,如果设置了ct_bottom_divider_style = SHADOW会导致xml中设置android:background失效,如果需要背景色,则根据需要设置

公共方法:

方法名称作用
setRightImageListener(listener: View.OnClickListener)设置最右侧图片点击
setRightImage2Listener(listener: View.OnClickListener)设置右起倒数第二图片点击
setMoreViewListener(listener: View.OnClickListener)设置更多点击
setRightTextListener(listener: View.OnClickListener)设置右侧显示的文本
setLeftArrowClickListener(listener: View.OnClickListener)设置左侧箭头点击,默认有点击事件,点击后结束当前所在Activity
setLeftTextViewClickListener(listener: View.OnClickListener)设置左侧文本点击,默认有点击事件,点击后结束当前所在Activity
setLeftArrowColor(@ColorRes leftArrowColor: Int)设置左侧箭头颜色
setRightTextVisible(visible: Int)设置右侧文本控件是否显示
setRightImageVisible(visible: Int)设置最右侧图片控件是否显示
setRightImage2Visible(visible: Int)设置右起倒数第二图片控件是否显示
setRightText(text: String)设置右侧显示文本
setRightTextColor(@ColorInt rightTextColor: Int)设置右侧文颜色
setRightImageDrawable(@DrawableRes drawableId: Int)设置右侧图片控件显示图片
setRightImageCheckedDrawable(@DrawableRes drawableId: Int)设置右侧图片控件显示选中图片
setRightImageChecked(checked:Boolean)设置右侧图片控件是否显示选中效果
getRightImageChecked()获取右侧图片控件是否选中
setRightImage2Drawable(@DrawableRes drawableId: Int)设置右起倒数第二图片控件显示图片
setRightImage2CheckedDrawable(@DrawableRes drawableId: Int)设置右起倒数第二图片控件显示选中图片
setRightImage2Checked(checked:Boolean)设置右起倒数第二图片控件是否显示选中效果
getRightImage2Checked()获取右起倒数第二图片控件是否选中
setCenterText(text: String)设置中间文本内容
setCenterTextColor(@ColorInt centerTextColor: Int)设置中间文颜色
setLeftText(text: String)设置左侧文本内容
setLeftTextColor(@ColorInt leftTextColor: Int)设置左侧文颜色
setLeftArrowVisible(visible: Int)设置左侧箭头是否显示
setMoveViewVisible(visible: Int)设置右边更多按钮是否显示

DanceView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity1

    <cn.lvsong.lib.library.view.DanceView
        android:layout_width="@dimen/width_40"
        android:layout_height="@dimen/height_40"
        android:layout_marginStart="@dimen/padding_40"
        android:layout_marginTop="@dimen/padding_10"
        app:dv_height_ratio="0.7"
        app:dv_pillar_color="@color/color_2878FF"
        app:dv_pillar_count="4"
        app:dv_pillar_duration="1200"
        app:dv_space_ratio="0.5" />

属性介绍:

属性名称取值类型取值和作用
dv_pillar_countinteger柱子数量,默认是4个
dv_pillar_durationinteger动画执行时间,默认1000毫秒
dv_space_ratiofloat空白间隔与柱子宽的比率,默认0.8
dv_height_ratiofloat柱子高度与控件高度的比率,默认0.8
dv_pillar_colorcolor柱子颜色,默认是红色

公共方法:

方法名称作用
startAnimator()开始动画,如果控件可见就会自动执行,不必手动调用
cancelAnimator()取消动画,如果控件不可见就会自动执行,不必手动调用

ExpandaleTextView

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity4

        etv_text_view.setOriginalText("据海关总署网站9月18日消息,因从印度尼西亚进口1批冻带鱼1个外包装样本检出新冠病毒核酸阳性,根据海关总署公告2020年第103号的规定,全国海关自即日起暂停接受印度尼西亚PT.PUTRI INDAH(注册编号为CR010-02)水产品生产企业产品进口申报1周,期满后自动恢复。")

属性介绍:

属性名称取值类型取值和作用
etv_collapse_max_linesinteger折叠时文本显示行数,默认3行
etv_expand_drawablereference展开时图标
etv_collapse_drawablereference折叠时图标
etv_switch_modeenum显示模式,TEXT(文本),ICON(图标)
etv_expand_textreference|string展开时文本,默认文本为: 收起 ,TEXT模式下有效
etv_collapse_textreference|string折叠时文本,默认文本为: 展开 ,TEXT模式下有效
etv_expand_text_colorcolor展开文本颜色,默认#2878FF ,TEXT模式下有效
etv_collapse_text_colorcolor折叠文本颜色,默认#2878FF ,TEXT模式下有效

公共方法:

FixedCursorEditText

方法名称作用
initWidth(int width)初始化TextView的可展示宽度
setHasAnimation(boolean hasAnimation)设置是否有动画,默认false
setMaxLines(int maxLines)设置折叠时显示的最多行数
setOpenSuffix(String openSuffix)设置展开后缀
setCloseSuffix(String closeSuffix)设置收起后缀
setOpenSuffixColor(@ColorInt int openSuffixColor)设置展开后缀文本颜色
setCloseSuffixColor(@ColorInt int closeSuffixColor)设置收起后缀文本颜色
setCloseInNewLine(boolean closeInNewLine)是否在展开时 对折叠文本/图标 另起一行

用法:

    <cn.lvsong.lib.library.view.FixedCursorEditText
        android:id="@+id/et_right_name_menu"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:contentDescription="@null"
        android:gravity="center_vertical|end"
        android:maxLines="1"
        android:textColor="@color/color_333333"
        android:textCursorDrawable="@drawable/ic_fixed_edit_cursor_bg"
        android:textSize="@dimen/text_size_14"/>

作用介绍:

Android 处理EditText光标显示在hint文字之前的问题,即输入之前光标在提示文本最前面,写入文字后光标跑到了输入文本后面, 修改为输入前光标在提示文本末尾

公共方法:

暂无

JAlertDialog

用法:

具体参考: cn.lvsong.lib.demo.CustomActivity1

        mExitDialog = JAlertDialog.Builder(this@CustomActivity1)
            .setCancelable(false) //设置是否点击外面可以取消
            .setContentView(view) // 绑定视图,可以是view也可以是layout资源文件
            .setHasAnimation(false) // 是否有动画效果,如果不调用setAnimation()则使用默认的 
//            .setAnimation() // 设置动画效果
            .setWidthAndHeight( // 设置弹框大小
                DensityUtil.getScreenWidth() - DensityUtil.dp2pxRtInt(38F) * 2,
                DensityUtil.dp2pxRtInt(130F)
            )
            //            .setText() // 可以放入TextView的id 和 在此控件显示的内容
            .setOnClick(R.id.btn_cancel_exit_dialog) // 设置点击的按钮ID,注意下面onClick(view: View, position: Int)中position和这里添加顺序有关
            .setOnClick(R.id.btn_sure_exit_dialog)// 设置点击的按钮ID,注意下面onClick(view: View, position: Int)中position和这里添加顺序有关
            .setOnJAlertDialogCLickListener(object : OnJAlertDialogCLickListener {
                override fun onClick(view: View, position: Int) {
                    // 参数中 position和添加点击按钮顺序有关
                    mExitDialog.dismiss()
                }
            })
            .create() // 这里调用create()则返回dialog
//            .show() // 这里调用show()则直接显示

属性介绍:

暂无

公共方法:

方法名称作用
setContentView(view: View)设置Dialog的视图
setContentView(layoutResId: Int)设置Dialog的视图
setCancelable(cancelable: Boolean)设置在弹框外面是否可以点击取消
setText(@IdRes viewId: Int, text: CharSequence)放入TextView的id 和 在此控件显示的内容
setFromTop(marginTop: Int)距离顶部距离,此时则弹框顶部显示
setFromBottom()设置Dialog在底部显示
setAnimation(@StyleRes styleAnim: Int)设置Dialog动画
setHasAnimation(hasAnimation: Boolean)设置是否使用动画,默认是true
setFullWidth()设置Dialog宽度占满
setWidthAndHeight(width: Int, height: Int)设置Dialog宽高
setOnClick(@IdRes viewId: Int)设置Dialog点击View
setOnJAlertDialogCLickListener(onJAlertDialogCLickListener: OnJAlertDialogCLickListener)设置点击事件
setOnCancelListener(onCancelListener: DialogInterface.OnCancelListener)设置取消Dialog事件
setOnOnDismissListener(onDismissListener: DialogInterface.OnDismissListener)设置Dialog消失回调
setOnKeyListener(onKeyListener: DialogInterface.OnKeyListener)设置Dialog OnKeyListener
create()生成Dialog返回
show()显示Dialog并返回
delayShow(delay: Int)延迟显示,必须 Dialog 来调用

由于字数限制,还有很多没有列出,大家可以去 Github看看,喜欢或者用得上记得点赞支持,谢谢!