您的位置:首页 > 移动开发 > Android开发

Android Viewbadger 实现消息数字提示

2015-01-12 16:56 453 查看
Code
Issues11
Pull
Requests0

Pulse
Graphs


HTTPS clone URL

You can clone with HTTPS orSubversion.
Clone
in Desktop Download
ZIP

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

21 commits

2 branches

0 releases

1 contributor

Java 100%

Java


branch: master

android-viewbadger/

1
comment

added
note on action bar limitations

latest
commit e08c3a78cb


jgilfelt authored on
12 Jan 2013

libmoved
packaged jar to resolve build issue with recent ADT
2 years ago
resnew
constructor and logic to better handle TabWidget target, addition…
3 years ago
srcallow
margins to be set independently, center position option,
3 years ago
.classpathmoved
packaged jar to resolve build issue with recent ADT
2 years ago
.gitignorefirst
commit
3 years ago
.projectfirst
commit
3 years ago
AndroidManifest.xmlREADME.markdown
update
3 years ago
LICENSEfirst
commit
3 years ago
README.markdownadded
note on action bar limitations
2 years ago
proguard.cfgfirst
commit
3 years ago
project.propertiesupdate
for tools r14
3 years ago


README.markdown


Android
ViewBadger

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





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 of
TextView
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
plaincopy

BadgeView badgeView = new BadgeView(MainActivity.this, iv1);

badgeView.setText("5");

badgeView.show();

然后是添加文字:

[java] view
plaincopy

BadgeView badgeView = new BadgeView(MainActivity.this, iv2);

badgeView.setText("新消息");

badgeView.setTextSize(8.5f);

badgeView.setTextColor(Color.DKGRAY);

badgeView.show();

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

[java] view
plaincopy

BadgeView badgeView2 = new BadgeView(MainActivity.this, iv3);

badgeView2.setBackgroundResource(R.drawable.noread);

badgeView2.show();

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

[java] view
plaincopy

badgeView.setVisibility(View.GONE);

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

源码下载地址:

http://download.csdn.net/detail/t12x3456/5983875
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: