Android BGABadgeView:BGABadgeLinearLayout以整体线性布局作为BadgeView(3)

Android BGABadgeView不仅可以把某个View作为Badge,也可以把一个完整的线性布局作为BadgeView。这要用到BGABadgeLinearLayout。

我写一个例子。

写布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="zhangphil.demo.MainActivity"> <cn.bingoogolapple.badgeview.BGABadgeLinearLayout
android:id="@+id/badge"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="@android:color/holo_blue_light" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示/隐藏小红点"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Java代码:

package zhangphil.demo;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View; import cn.bingoogolapple.badgeview.BGABadgeLinearLayout;
import cn.bingoogolapple.badgeview.BGABadgeViewHelper; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final BGABadgeLinearLayout badge = (BGABadgeLinearLayout) findViewById(R.id.badge);
badge.showCirclePointBadge(); //初始化
badge.showTextBadge("9");
badge.getBadgeViewHelper().setBadgeTextSizeSp(15);
badge.getBadgeViewHelper().setBadgeTextColorInt(Color.WHITE);
badge.getBadgeViewHelper().setBadgeBgColorInt(Color.RED);
badge.getBadgeViewHelper().setDragable(true);
badge.getBadgeViewHelper().setBadgePaddingDp(6);
badge.getBadgeViewHelper().setBadgeBorderWidthDp(2);
badge.getBadgeViewHelper().setBadgeBorderColorInt(Color.WHITE);
badge.getBadgeViewHelper().setBadgeGravity(BGABadgeViewHelper.BadgeGravity.RightTop); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (badge.isShowBadge())
badge.hiddenBadge();
else {
badge.showCirclePointBadge(); //注意带上这个显示数字,否则将变成空
badge.showTextBadge("99+");
}
}
});
}
}

代码运行结果:

附录文章:

1,《仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)》链接地址:http://blog.csdn.net/zhangphil/article/details/43702953 


2,《仿短信条目右上角的红色小圆球提示气泡》链接地址:http://blog.csdn.net/zhangphil/article/details/43667727

3,《Android BGABadgeView:新消息/未接来电/未读消息/新通知圆球红点提示(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/51822514

4,《Android BGABadgeView:显示提示数字(2)》链接地址:http://blog.csdn.net/zhangphil/article/details/51828808

最新文章

  1. 微信官方demo(php)
  2. linux下内网端口转发工具:linux版lcx [实现远程内网维护]
  3. mac os x安装php7.0和phalcon3.0
  4. C# System.Diagnostics.Stopwatch 类
  5. WPF如何用TreeView制作好友列表、播放列表
  6. aircrack-ng 字典破解WPA / WPA2
  7. Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
  8. 来自内部的XSS攻击的防范
  9. appledoc:Objective-C注释文档生成工具
  10. 从MySQL随机选取数据
  11. 基于ARM的车牌识别技术研究与实现
  12. Spring中@Component注解,@Controller注解详解
  13. advanceskeleton插件分身体和表情单独绑定的时候合并表情步骤
  14. PaddlePaddle Perceptron Example
  15. pytorch基础教程1
  16. 【UI测试】--多窗口&系统资源
  17. postman环境变量的设置
  18. Guidelines for Installing Oracle HR Sample Schemas
  19. acm专题---键树
  20. Linode之使用UE实现SSH连接

热门文章

  1. bzoj1415 [Noi2005]聪聪和可可【概率dp 数学期望】
  2. Tian Ji -- The Horse Racing HDU - 1052
  3. Mondriaan&#39;s Dream POJ - 2411
  4. html下的图片链接有边框的解决方法
  5. CentOS系统里如何正确取消或者延长屏幕保护自动锁屏功能(图文详解)
  6. 块级元素的text-align对行内元素和果冻元素(inline-block)的作用
  7. 纯css实现的三级水平导航菜单
  8. 一种结合hudson的算法自动化测试构想
  9. 鸢尾花数据集-iris.data
  10. 看到了一篇不错的tensorflow文章