android:tag 字符,Android标签AndroidTagGroup(系列1)



Android标签AndroidTagGroup(系列1)

AndroidTagGroup是github上开源的标签库,效果图如下:

3ca10e61c1ec0ebd29c9045d11d784c2.png

AndroidTagGroup在github上的项目主页是:https://github.com/2dxgujun/AndroidTagGroup

AndroidTagGroup的使用:

(1)在布局文件写AndroidTagGroup,比如:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:scrollbars="vertical" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="缺省(默认)" />

android:id="@+id/tag_group"

style="@style/TagGroup" />

android:layout_width="match_parent"

android:layout_height="1dip"

android:background="?android:attr/listDivider" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="TagGroup.Beauty_Red" />

android:id="@+id/tag_group_beauty"

style="@style/TagGroup.Beauty_Red" />

android:layout_width="match_parent"

android:layout_height="1dip"

android:background="?android:attr/listDivider" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="TagGroup.Beauty_Red.Inverse" />

android:id="@+id/tag_group_beauty_inverse"

style="@style/TagGroup.Beauty_Red.Inverse" />

android:layout_width="match_parent"

android:layout_height="1dip"

android:background="?android:attr/listDivider" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="小号" />

android:id="@+id/tag_group_small"

style="@style/TagGroup.Small" />

android:layout_width="match_parent"

android:layout_height="1dip"

android:background="?android:attr/listDivider" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="大号" />

android:id="@+id/tag_group_large"

style="@style/TagGroup.Large" />

(2)然后在Java代码中为其设置标签内容,比如随意设置一些标签字段:

import android.app.Activity;

import android.os.Bundle;

import android.widget.Toast;

import me.gujun.android.taggroup.TagGroup;

public class MainActivity extends Activity {

private TagGroup mDefaultTagGroup;

private TagGroup mSmallTagGroup;

private TagGroup mLargeTagGroup;

private TagGroup mBeautyTagGroup;

private TagGroup mBeautyInverseTagGroup;

private String[] tags = null;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// 标签里面的字符串。

tags = new String[] { "Zhang", "Phil", "ZhangPhil", "CSDN Zhang Phil", "Android", "移动", "CSDN", "Android研发" };

mDefaultTagGroup = (TagGroup) findViewById(R.id.tag_group);

mDefaultTagGroup.setTags(tags);

mSmallTagGroup = (TagGroup) findViewById(R.id.tag_group_small);

mSmallTagGroup.setTags(tags);

mLargeTagGroup = (TagGroup) findViewById(R.id.tag_group_large);

mLargeTagGroup.setTags(tags);

mBeautyTagGroup = (TagGroup) findViewById(R.id.tag_group_beauty);

mBeautyTagGroup.setTags(tags);

mBeautyInverseTagGroup = (TagGroup) findViewById(R.id.tag_group_beauty_inverse);

mBeautyInverseTagGroup.setTags(tags);

// 为每一个标签增加点击事件。

mDefaultTagGroup.setOnTagClickListener(mTagClickListener);

mSmallTagGroup.setOnTagClickListener(mTagClickListener);

mLargeTagGroup.setOnTagClickListener(mTagClickListener);

mBeautyTagGroup.setOnTagClickListener(mTagClickListener);

mBeautyInverseTagGroup.setOnTagClickListener(mTagClickListener);

}

private TagGroup.OnTagClickListener mTagClickListener = new TagGroup.OnTagClickListener() {

@Override

public void onTagClick(String tag) {

Toast.makeText(getApplicationContext(), tag, Toast.LENGTH_SHORT).show();

}

};

}

可以通过为其增加点击事件以响应用户的点击事件。

如果需要再次二次定制AndroidTagGroup样式,则需要在AndroidTagGroup 的库项目中的res/values/styles.xml改写某些属性字段值:

04b75432a2b4de4ab9ca25fa9493da7b.png

比如,定义边线宽度的是:

1dp

又比如,标签的边线颜色和里面的文本颜色是:

#0097a7

#0097a7

届时可以根据自己需要再次定制。

另外,个别标签样式(如

1dp

附录一些AndroidTagGroup style属性定义设置字段(AndroidTagGroup库中的res/values/styles.xml文件代码):

<?xml version="1.0" encoding="utf-8"?>

match_parent

wrap_content

false

@string/add_tag

#0097a7

#0097a7

#FFFFFF

#AAAAAA

#80000000

#DE000000

#49C120

#FFFFFF

#FFFFFF

#49C120

#EDEDED

1dp

13sp

8dp

4dp

12dp

3dp

10sp

6dp

3dp

8dp

2dp

1dp

15sp

9dp

5dp

14dp

4dp

#FF3D7F

#FF3D7F

#FF3D7F

#FF3D7F

#FF3D7F

#FFFFFF

#FF3D7F

#80FFFFFF

#DEFFFFFF

#FF3D7F

#FF3D7F

#FF3D7F

#FFFFFF

#FF99B1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值