TextView實現消息小紅點(BadgeView)

不知從何時開始,消息提示都以紅點的方式出現了。①像這樣的圓圈包着數字。今天我們來聊一聊如何實現……

這裏不討論拖拽特效,只實現顯示效果,需要拖拽特效的可以看看github的開源項目badgeVIew

背景文件

在drawable文件夾下新建一個badge_bg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="false">
    <!--這裏設置badge的顏色-->
    <solid android:color="@color/red" />

    <!--這裏設置badge的大小-->
    <size
        android:width="20dp"
        android:height="20dp" />
</shape>

使用

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:gravity="center"
    android:textColor="@color/white"
    android:text="23"
    android:background="@drawable/badge_bg" />

這樣就實現了一個簡單的紅點消息顯示啦!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章