android 消息提示红点(或者文字)

本文介绍了一种在Android应用中实现即时通讯(IM)消息红点提示的方法,使用ConstraintLayout和自定义形状实现视觉效果,适用于多种控件上显示未读消息提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

相信很多人都遇到过在一个控件上显示IM消息提示的功能吧(红点或者是数字)

随便搜索下会出来好多,使用自定义控件,FrameLayout都可以实现。

还有就是约束布局实现(ConstraintLayout)

im_hint.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">

<TextView
    android:id="@+id/projectDynamicTV"
    android:layout_width="@dimen/name_dp60"
    android:layout_height="@dimen/name_dp30"
    android:background="@color/color50A"
    android:gravity="center"
    android:text="消息红点"
    android:textColor="@color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/dot_red"
    app:layout_constraintBottom_toTopOf="@id/projectDynamicTV"
    app:layout_constraintLeft_toRightOf="@id/projectDynamicTV"
    app:layout_constraintRight_toRightOf="@id/projectDynamicTV"
    app:layout_constraintTop_toTopOf="@id/projectDynamicTV" />


</android.support.constraint.ConstraintLayout>
复制代码

dot_red.xml

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#E95548"/>
<size
    android:width="9dp"
    android:height="9dp"></size>
 </shape>
复制代码

实现的方法很多,以上只是我的实现方式,希望帮到你

转载于:https://juejin.im/post/5bcd6f5c6fb9a05cd8495eee

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值