:heartpulse:BGABadgeView-Android:heartpulse:

December 10, 2024 · View on GitHub

Android Arsenal License Download

English Document

react-native-bga-badge-view

demo中演示了:

  • 微博底部tab显示最新微博条数
  • 微博列表用户头像显示显示右下角vip徽章
  • 微信消息界面用户新消息
  • 微信消息界面订阅号新消息
  • 使用v4包中的RoundedBitmapDrawable制作圆角头像
  • 拖拽删除徽章

爆炸效果参考的 ExplosionField 改成了只有一个View的情况,只刷新徽章附近的区域

效果图

badgeview

点击下载 Apk 或扫描下方二维码安装体验

Demo

添加 Gradle 依赖

  • maven { url 'https://jitpack.io' } 加入到 repositories 中
  • 添加如下依赖,末尾的「latestVersion」指的是徽章Download里的版本名称,请自行替换。
dependencies {
    implementation 'com.github.bingoogolapple.BGABadgeView-Android:api:latestVersion'
    annotationProcessor 'com.github.bingoogolapple.BGABadgeView-Android:compiler:latestVersion'
}

初始化徽章控件

  1. 在项目任意一个类上面添加 BGABadge 注解,例如新建一个类 BGABadgeInit 专门用于初始化徽章控件
  2. 需要哪些类具有徽章功能,就把那些类的 Class 作为 BGABadge 注解的参数「下面的代码块给出了例子,不需要的可以删掉对应的行」
@BGABadge({
        View.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeView,不想用这个类的话就删了这一行
        ImageView.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeImageView,不想用这个类的话就删了这一行
        TextView.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeFloatingTextView,不想用这个类的话就删了这一行
        RadioButton.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeRadioButton,不想用这个类的话就删了这一行
        LinearLayout.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeLinearLayout,不想用这个类的话就删了这一行
        FrameLayout.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeFrameLayout,不想用这个类的话就删了这一行
        RelativeLayout.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeRelativeLayout,不想用这个类的话就删了这一行
        FloatingActionButton.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeFloatingActionButton,不想用这个类的话就删了这一行
        ...
        ...
        ...
})
public class BGABadgeInit {
}
  1. 再 AS 中执行 Build => Rebuild Project
  2. 经过前面三个步骤后就可以通过「cn.bingoogolapple.badgeview.BGABadge原始类名」来使用徽章控件了

接口说明

/**
 * 显示圆点徽章
 */
void showCirclePointBadge();

/**
 * 显示文字徽章
 *
 * @param badgeText
 */
void showTextBadge(String badgeText);

/**
 * 隐藏徽章
 */
void hiddenBadge();

/**
 * 显示图像徽章
 *
 * @param bitmap
 */
void showDrawableBadge(Bitmap bitmap);

/**
 * 设置拖动删除徽章的代理
 *
 * @param delegate
 */
void setDragDismissDelegage(BGADragDismissDelegate delegate);

/**
 * 是否显示徽章
 *
 * @return
 */
boolean isShowBadge();

/**
 * 是否可拖动
 *
 * @return
 */
boolean isDraggable();

/**
 * 是否正在拖动
 *
 * @return
 */
boolean isDragging();

自定义属性说明

属性名说明默认值
badge_bgColor徽章背景色Color.RED
badge_textColor徽章文本的颜色Color.WHITE
badge_textSize徽章文本字体大小10sp
badge_verticalMargin徽章背景与宿主控件上下边缘间距离4dp
badge_horizontalMargin徽章背景与宿主控件左右边缘间距离4dp
badge_padding徽章文本边缘与徽章背景边缘间的距离4dp
badge_gravity徽章在宿主控件中的位置BGABadgeImageView和BGABadgeRadioButton是右上方,其他控件是右边垂直居中
badge_draggable是否开启拖拽删除徽章false
badge_isResumeTravel拖拽徽章超出轨迹范围后,再次放回到轨迹范围时,是否恢复轨迹false
badge_borderWidth徽章描边宽度0dp
badge_borderColor徽章描边颜色Color.WHITE
badge_dragExtra触发开始拖拽徽章事件的扩展触摸距离4dp

作者联系方式

个人主页邮箱
bingoogolapple.cnbingoogolapple@gmail.com
个人微信号微信群公众号
个人微信号微信群公众号
个人 QQ 号QQ 群
个人 QQ 号QQ 群

打赏支持作者

如果您觉得 BGA 系列开源库或工具软件帮您节省了大量的开发时间,可以扫描下方的二维码打赏支持。您的支持将鼓励我继续创作,打赏后还可以加我微信免费开通一年 上帝小助手浏览器扩展/插件开发平台 的会员服务

微信QQ支付宝
微信QQ支付宝

作者项目推荐

License

Copyright 2015 bingoogolapple

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.