我怎样才能通知栏永久显示的文字? [英] How can i show text permanently in the notification bar?
问题描述
我想问一下它是如何可能在通知栏永久显示的文字?
由setTicker()方法设置的股票在几秒钟后消失。
I'd like to ask how it is possible to show text permanently in the notification bar? The ticker set by the setTicker() method disappears after a few seconds.
我的目标是,以显示通知栏的当前温度。什么是做到这一点的最佳解决方案?也许有传递文本到setSmallIcon()方法的方法吗?
My goal is to show the current temperature in the notification bar. What would be the best solution to do this? Maybe there's a way to pass text to the setSmallIcon() method?
下面是我的通知code:
Here's my notification code:
NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getApplicationContext());
notBuilder.setContentText("text");
notBuilder.setContentTitle("title");
notBuilder.setSmallIcon(android.R.color.transparent);
notBuilder.setTicker("ticker");
notBuilder.setOngoing(true);
int notID = 8;
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
nm.notify(notID, notBuilder.build());
(有没有更好的解决隐藏的小图标?它是透明的这种方式,但仍占用的地方)
(is there a better solution to hide the small icon? it's transparent this way but still takes up the place)
在此先感谢!
推荐答案
这是唯一可以显示在状态栏永久的图标。由股票设置的文本不能是永久性的,只有在一段看起来如果通知显示第一次。这是由设计,因为用户通常不希望永久性的消息而隐藏状态栏。
It's only possible to show a permanent icon in the status bar. The text set by the ticker can't be permanent and appears only for a period if the notification shows the first time. This is by design because the user usually don't want a permanent message which "hides" the status bar.
要隐藏的小图标完全可以使用 NotificationBuilder.setPriority(INT)旗 Notification.PRIORITY_MIN 。通过这种方式,通知将被减少到最低限度,其包括图标的遮盖。但这种方法只适用于API提供16+。低于这个水平,你可以设置对透明图标(你已经做了),但图标的空间就像一个占位符,不能删除。也许这回答是您的具体情况有帮助的,但它只是移动图标空间到另一个区域。
To hide the small icon completely you could use NotificationBuilder.setPriority(int) with the flag Notification.PRIORITY_MIN. This way the notification will be reduced to a minimum, which includes the hiding of the icon. But this method is only available in API 16+. Below this level you can set a transperent icon (what you already did), but the space for the icon acts like a placeholder and can't be deleted. Maybe this answer is helpful for your situation, but it just moves the icon space to another area.
这篇关于我怎样才能通知栏永久显示的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!