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 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.youkuaiyun.com/detail/shi508181017/5902419
其用法非常简单:
首先是添加数字:
- BadgeView badgeView = new BadgeView(MainActivity.this, iv1);
- badgeView.setText("5");
- badgeView.show();
然后是添加文字:
- BadgeView badgeView = new BadgeView(MainActivity.this, iv2);
- badgeView.setText("新消息");
- badgeView.setTextSize(8.5f);
- badgeView.setTextColor(Color.DKGRAY);
- badgeView.show();
最后是添加特定图标,只需对应drawable的id即可
- BadgeView badgeView2 = new BadgeView(MainActivity.this, iv3);
- badgeView2.setBackgroundResource(R.drawable.noread);
- badgeView2.show();
隐藏/去掉提醒图标或者数字(同正常View隐藏的方法);
- badgeView.setVisibility(View.GONE);
怎么样,只要是View对象即可添加提醒图标或者数字,是不是很方便,.赶紧用一下吧.
源码下载地址:
http://download.youkuaiyun.com/detail/t12x3456/5983875