Android Viewbadger 实现消息数字提示

A simple way to "badge" any given Android view at runtime without having to cater for it in layout
 branch: master 

 README.markdown

Android ViewBadger

A simple way to "badge" any given Android view at runtime without having to cater for it in layout.

Demos  ListAdapter

Note: If your aim is to replicate the iOS icon and TabBar badge UI for notifications, consider using Android UI conventions such as the number field of the Notification class rather than this method.

Usage

Simple example:

View target = findViewById(R.id.target_view);
BadgeView badge = new BadgeView(this, target);
badge.setText("1");
badge.show();

This project contains a fully working example application. Refer to the DemoActivity class for more custom badge examples, including custom backgrounds and animations. BadgeView is a subclass ofTextView so you can use all of TextView's methods to style the appearance of your badge.

To use ViewBadger in your own Android project, simply copy android-viewbadger.jar (available from this repository's package downloads) into your project's /libs directory and add it to the build path.

Current Limitations

  • Badging Action Bar items is currently not supported #2
  • Badging views inside RelativeLayout with dependencies may break alignment #1

Credits

Author: Jeff Gilfelt

The code in this project is licensed under the Apache Software License 2.0. 
Copyright (c) 2011 readyState Software Ltd.


android的viewbadger"徽章"任何给定的Android视图,而无需在运行时布局,以迎合在一个简单的方法

2、使用方法

先导入android-viewbadger.jar 

然后直接在activity如下操作

View target = findViewById(控件id识别);//target为你想显示badges的控件
BadgeView badge = new BadgeView(this, target);badge.setText("1");
badge.show();//或者使用 badge .toggle();

扩展方法:setText(),

                 setTextColor(Color.BLUE),

                 setBadgeBackgroundColor(Color.YELLOW),

                 setTextSize(12),

                 toggle()等等;

3、资源下载地址:http://download.csdn.net/detail/shi508181017/5902419


其用法非常简单:

首先是添加数字:

[java]  view plain copy
  1.                BadgeView badgeView = new BadgeView(MainActivity.this, iv1);  
  2.                badgeView.setText("5");  
  3.                badgeView.show();  

然后是添加文字:

[java]  view plain copy
  1.               BadgeView badgeView = new BadgeView(MainActivity.this, iv2);  
  2. badgeView.setText("新消息");  
  3. badgeView.setTextSize(8.5f);  
  4. badgeView.setTextColor(Color.DKGRAY);  
  5. badgeView.show();  

最后是添加特定图标,只需对应drawable的id即可

[java]  view plain copy
  1.               BadgeView badgeView2 = new BadgeView(MainActivity.this, iv3);  
  2. badgeView2.setBackgroundResource(R.drawable.noread);  
  3. badgeView2.show();  

隐藏/去掉提醒图标或者数字(同正常View隐藏的方法);

[java]  view plain copy
  1. badgeView.setVisibility(View.GONE);  

 怎么样,只要是View对象即可添加提醒图标或者数字,是不是很方便,.赶紧用一下吧.


源码下载地址:

http://download.csdn.net/detail/t12x3456/5983875


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值