有没有办法在 Android 中的应用程序图标上添加徽章?
在 iPhone 上,您可以将编号徽章添加到应用程序图标。在黑莓手机上,我在程序中成功地将图像绘制到应用程序的图标上。我也想为 Android 做这个。我不想使用通知栏,因为它不是需要立即通知的东西。相反,我只是希望用户只需查看应用程序图标就能够看到应用程序中有多少新消息。
On the iPhone, you can add a numbered badge to the application icon. On BlackBerry, I've successfully painted an image onto the application's icon while in the program. I want to do this for Android as well. I don't want to use the notification bar, as it's not something that needs to be notified instantly. Instead, I just want the user to be able to see how many new messages are in the application just by looking at the application icon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不幸的是,Android 不允许更改应用程序图标,因为一旦程序编译,它就被密封在 APK 中。无法以编程方式将其更改为“可绘制”。
您可以通过使用小部件而不是图标来实现您的目标。小部件是高度可定制的,可以做你想做的事情。
这里有一个关于 iPhone 图标通知和使用小部件之间区别的简短讨论:
http:// /www.cnet.com/8301-19736_1-10278814-251.html
正如您所注意到的,使用小部件或图标实际上没有区别,因为它们可以具有相同的大小并且看起来相同。
Unfortunately, Android does not allow changing of the application icon because it's sealed in the APK once the program is compiled. There is no way to programmatically change it to a 'drawable'.
You may achieve your goal by using a widget instead of an icon. Widgets are highly customisable and can do what you want.
There's a short discussion about the difference between iPhone icon notification and using widgets here:
http://www.cnet.com/8301-19736_1-10278814-251.html
As you'll notice, there is virtually no difference between using a widget or an icon, since they can be the same size and look the same.
索尼的 Xperia Home 也可以这样做。我已经在博客上介绍了它 这里,但重要的部分如下。 Sony 设备使用名为
BadgeReciever
的类。在清单文件中声明
com.sonyericsson.home.permission.BROADCAST_BADGE
权限:向
BadgeReceiver
广播Intent
:完成。一旦此
Intent
被广播,启动器就会在您的应用程序图标上显示一个徽章。要再次删除徽章,只需发送一个新的广播,这次将
SHOW_MESSAGE
设置为 false:为了保持答案简短,我排除了有关如何发现此问题的详细信息,但这一切都可以在博客中找到。对于某人来说可能是一本有趣的读物。
我还发布了一个关于此的单独问题 此处,一旦获得允许,我将在那里添加完整答案(需要 10 点声誉才能在 8 小时内回答我自己的问题)。
This can also be done for Sony's Xperia Home. I've blogged about it here, but the important parts are below. Sony devices use a class named
BadgeReciever
.Declare the
com.sonyericsson.home.permission.BROADCAST_BADGE
permission in your manifest file:Broadcast an
Intent
to theBadgeReceiver
:Done. Once this
Intent
is broadcast the launcher should show a badge on your application icon.To remove the badge again, simply send a new broadcast, this time with
SHOW_MESSAGE
set to false:I've excluded details on how I found this to keep the answer short, but it's all available in the blog. Might be an interesting read for someone.
I've also posted a seperate SO question about this here and will add the full answer there once I'm allowed to (need 10 reputation to answer my own question within 8 hours).
ShortcutBadger 库使之成为可能,并可与 LG、Sony、Samsung、HTC 和其他自定义启动器配合使用。
它甚至可以在纯 Android 设备桌面上显示徽章计数。
更新应用程序图标中的徽章计数就像调用一样简单:
它包括一个演示应用程序,允许您测试其行为。
或者
您也可以尝试使用活动别名来执行此操作,但是在这种情况下,您需要创建带有徽章值的不同图标,如果您需要在 2 个不同的应用程序图标之间切换(需要为显示不同的图标,即更多图标=更多活动别名)。
ShortcutBadger library makes it possible and works with LG, Sony, Samsung, HTC and other custom Launchers.
It even has a way to display Badge Count in Pure Android devices desktop.
Updating the Badge Count in the application icon is as easy as calling:
It includes a demo application that allows you to test its behaviour.
OR
you can also try activity-alias to do so, but in this you need to create different icons with badge values ,it will work great in case- you need to switch between 2 different App icons (need to create different activity-alias for displaying different icon i.e more icons = more activity-alias).
华硕设备:
华为设备:
HTC 设备:
三星设备:
索尼设备:
小米设备:
Asus devices:
Huawei devices:
HTC devices:
Samsung devices:
Sony devices:
Xiaomi devices:
从 API 26 开始,现在正式支持:
要设置自定义号码,请在通知上调用 setNumber():
As of API 26, this is now officially supported:
To set a custom number, call setNumber() on the notification:
操作方法如下:
我认为还有一种方法可以在 LG 启动器上执行此操作,但尚未找到具体方法。
Here's how to do it for:
I think there's also a way to do it on the LG launcher, but haven't found out how yet.