第三方控件:消息数量控件BadgeView的使用

下载BadgeView.jar包,放在项目的libs下

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_badge_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context="cn.com.zt.qqdemo.BadgeViewActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/linear"
        >

    <Button
        android:id="@+id/btn_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button"
        />

    </LinearLayout>

</LinearLayout>

主代码

private BadgeView badgeView;

// 要关联的View
LinearLayout linear = (LinearLayout) findViewById(R.id.linear);
badgeView = new BadgeView(this);
// 与BadgeView进行关联
badgeView.setTargetView(linear);
// 设置小红点的位置
badgeView.setBadgeGravity(Gravity.RIGHT|Gravity.TOP);
// 设置小红点显示的消息数量
badgeView.setBadgeCount(7);

常用方法

// 设置哪个控件显示数字提醒,参数就是一个view对象
1. setTargetView(View)  
// 设置提醒的数字
2. setBadgeCount(int)
// 设置badgeview的显示位置 
3. setBadgeGravity(Gravity) 
// 设置badgeview的背景色,当然还可以设置背景图片
4. setBackgroundColor() 
// 设置背景图片
5. setBackgroundResource()
// 设置显示的字体 
6. setTypeface()
// 设置字体的阴影 
7. setShadowLayer() 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值