Android 優(yōu)美的自動(dòng)換行標(biāo)簽按鈕

廢話不多說(shuō) 先上圖

1.三種大小模式 ,依次小、中、大

image.png

image.png

image.png

2.設(shè)置圓角

image.png

自行設(shè)置圓角大小(僅在非圓角模式生效)

image.png

3.鏤空模式(圓角支持自定義)

image.png

4.在控件設(shè)置數(shù)據(jù)

<com.uni.taggroupview.TagView
            android:id="@+id/tag_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:textList="隨時(shí)可看,帶家私,帶家電,隨時(shí)可看,帶家私,帶家電,靠近地鐵,貴,大型購(gòu)物商場(chǎng),停車場(chǎng)"
            app:roundedCorners="5"
            app:isHollowOut="true"
            app:isRounded="false"
            app:sizeMode="large"
            />

5.在代碼設(shè)置數(shù)據(jù)

// 公開(kāi)設(shè)置數(shù)據(jù)方法
public void setDatas(List<String> texts) {
}

// 設(shè)置點(diǎn)擊回調(diào)
binding.tagView.setClickCallback((view, index) -> {
         Log.e("TAG", "onClick: "+index);
});
// 設(shè)置長(zhǎng)按回調(diào)
binding.tagView.setLongClickCallback((view, index) -> {
       Log.e("TAG", "onLongClick: "+index);
       return false;
});

6..文本顏色默認(rèn)白色 背景色默認(rèn)隨機(jī) 兩種顏色均可以指定

設(shè)置間距僅支持marginRight marginBottom; 也可以通過(guò)代碼來(lái)設(shè)置margin值

app:marginRight="5"
app:marginBottom="5"

7. v1.0.6增加兩種模式,背景色可定義為漸變背景,圓角可自定義

第一種 左側(cè)顯示單個(gè)字符,右側(cè)內(nèi)容,如下圖,默認(rèn)顯示第一個(gè)字符

image.png

代碼設(shè)置如下

<com.uni.taggroupview.TagView
            android:id="@+id/tag_view1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:isHollowOut="false"
            app:isRounded="false"
            app:roundedCorners="5"
            app:sizeMode="small"
            app:textList="隨時(shí)可看,帶家私,帶家電,隨時(shí)可看,帶家私,帶家電,靠近地鐵,貴實(shí)打?qū)?大型購(gòu)物商場(chǎng),停車場(chǎng)"
            app:marginRight="5"
            app:styleMode="1"
            />

8.第二種 左側(cè)顯示圖標(biāo),右側(cè)內(nèi)容,如下圖

image.png

代碼設(shè)置如下

 <com.uni.taggroupview.TagView
            android:id="@+id/tag_view2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:isHollowOut="false"
            app:isRounded="false"
            app:roundedCorners="5"
            app:sizeMode="small"
            app:textList="隨時(shí)可看,帶家私,帶家電,隨時(shí)可看,帶家私,帶家電,靠近地鐵,貴實(shí)打?qū)?大型購(gòu)物商場(chǎng),停車場(chǎng)"
            app:marginRight="5"
            app:styleMode="2"
            />

自定義圓角

image.png

9.如果不喜歡漸變 色,可以只設(shè)置一種顏色,如下

        int[] color=new int[]{Color.RED};
        int[] color2=new int[]{Color.BLUE};

        binding.tagView1.setLeftColor(color);
        binding.tagView1.setRightColor(color2);

        binding.tagView2.setLeftColor(color);
        binding.tagView2.setRightColor(color2);

10.添加依賴

implementation 'com.gitee.Pino_W:tag_group:v1.0.9'

11.gitee地址 https://gitee.com/Pino_W/tag_group.git

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容