# TagTextView-android **Repository Path**: tongfu/tag-text-view-android ## Basic Information - **Project Name**: TagTextView-android - **Description**: No description available - **Primary Language**: Android - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-22 - **Last Updated**: 2024-03-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 什么是TagTextView? 1. TagTextView是一个带标签的TextView,继承自TextView 2. TagTextView可以实现在一段文字头部或者尾部显示标签 3. TagTextView也可以实现在一段文字上显示一个或者多个标签 4. TagTextView更可以添加标签到你想要的任意位置 5. TagTextView还能添加图片作为标签显示 6. TagTextView同时还支持自定义布局和样式,非常灵活 ![avatar](images/screen.png) # 如何使用TagTextView ### 在build.gradle中添加依赖 > 当前版本:[![Download](https://api.bintray.com/packages/xiaozhiguang666/maven/TagTextView/images/download.svg) ](https://bintray.com/xiaozhiguang666/maven/TagTextView/_latestVersion) ``` compile 'com.xiaozhiguang.library:TagTextView:1.0.0' ``` ### 或者直接下载libs库然后引用到项目中 * [点击下载libs库](https://github.com/xiaozhiguang/TagTextView/archive/master.zip) > 在你的布局中引用自定义view ``` ``` > 在你的Activity中初始化TagTextView ``` private TagTextView tv_with_tags; tv_with_tags = findViewById(R.id.tv_with_tags); ``` > 给TagTextView设置标签和内容和样式等相关属性 ``` // 头部标签 tv_with_tags.setSingleTagAndContent("标签", "这是一个带有tag的TextView"); // 尾部标签 tv_with_single_tags_end.setTagsIndex(TagTextView.TAGS_INDEX_AT_END); tv_with_single_tags_end.setSingleTagAndContent("尾部Tags", "这是一个尾部带有tag的TextView"); // 多个标签 List tags = new ArrayList<>(); tags.add("标签1"); tags.add("标签2"); tags.add("标签3"); tags.add("标签4"); tv_with_multiple_tags.setMultiTagAndContent(tags, "这是一个带有多个tag的TextView"); // 设置标签的字体大小和颜色 tv_with_single_tags_anyway.setTagTextSize(12); tv_with_single_tags_anyway.setTagTextColor("#FF0000"); // 自定义标签样式 tv_with_single_tags_anyway.setTagsBackgroundStyle(R.drawable.shape_tags_bg); // 自定义位置的标签 tv_with_single_tags_anyway.setTagAnyway(4, 10, "这是一个可以自己设置标签位置的TextView"); // 图片标签 tv_with_image_tags.setTagImageStart(this, R.mipmap.icon_close, " 这是一个添加图片tag的TextView", 20, 20); ``` # Tips 1. 小提示:自带的ImageSpan显示出来的标签可能会出现与文字内容布局中的情况,所以采用了自定义CenterImageSpan的方法来达到标签与文字内容居住的效果。 2. TagTextView还有很多的地方可以拓展,大家有兴趣的可以试一试,另外大家有什么不懂的地方可以提问到[issues](https://github.com/xiaozhiguang/TagTextView/issues), 我会尽量解决您的问题。