AndroidTagView是一个非学好用的标签控件。他支持自定义的标签视图,支持添加标签,点击,长按弹出删除对话框,以及拖拽排序等功能。下面简单介绍一下使用:
1.添加依赖:
dependencies {
implementation (compile) 'co.lujun:androidtagview:1.1.4'
}
2.添加到布局:
<co.lujun.androidtagview.TagContainerLayout
android:id="@+id/tclContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/px10"
app:container_enable_drag="false" // 是否可以拖拽,默认false
app:horizontal_interval="@dimen/px5" // 水平间隔,默认 5dp
app:vertical_interval="@dimen/px5" // 垂直间隔,默认 5dp
app:tag_text_color="@color/colorPrimary" // tag文字颜色
app:tag_clickable="false"/> // tag是否可以点击 默认不可点击
3. 在页面中的展示:
TagContainerLayout mTclContent = findViewById(R.id.tclContent);
mTclContent.setTags(List<String> tags);
能过以上方法就能够将Tag展示在页面中。
4.对其进行自定义的样式设置:
如果你对于英文文档不怎么熟悉也可以到其他朋友写的文章里面去查找:
(不好放别人的文章信息,可以查询AndroidTagView云标签)
// 如果在添加自己的Theme则先将原来的Theme设NONE
mTclContent.setTheme(ColorFactory.NONE);
mTclContent.setBackgroundColor(getResources().getColor(R.color.white));
你可以通过上面两个地方去查看更多关于AndroidTagView的效果及他的点击事件。
设置每个Item的不同颜色功能:
tagContainerLayout.setTags(List<String>); for (int i = 0; i < tagContainerLayout.getChildCount(); i++) { TagView view = (TagView) tagContainerLayout.getChildAt(i); if (i == 0) { view.setBackgroundResource(R.drawable.label); // 设置背景 view.setTagTextColor(getResources().getColor(R.color.pro)); // 设置字体颜色 } }
在这里也不进行多写了,主要是想写一下可能会出现的问题:
当然在实现TagView的时候也出现了一些小小的问题
1.他要分别去设置Tag的背景,边框和布局的背景,边框。才能够实现自己所要的功能。
(白色的背景,无边框,加上Tag的背景等)
mTclContent.setBackgroundColor(getResources().getColor(R.color.white)); // 设置背景
mTclContent.setBorderColor(mContext.getResources().getColor(R.color.white)); // 设置边框
mTclContent.setTagBackgroundColor(mContext.getResources().getColor(R.color.white)); // 设置Tag背景
mTclContent.setTagBorderColor(mContext.getResources().getColor(R.color.white)); // 设置Tag边框
mTclContent.setTagHorizontalPadding(10); // 设置TAG的横向间距
mTclContent.setTagVerticalPadding(10); // 设置TAG的纵向间距
mTclContent.setTagBackgroundResource(R.drawable.btn_login_col); // 设置TAG的样式
不过就在不久前找到了一个新的控件也许可以让人耳目一新呢!
FlowLayout标签布局
目前没有试过是否好用,等下一次试用过去将感悟写到里面去。