Android 如何在通知栏中创建文本?
正如你从这张图片中看到的,我想创建一个红色圆圈。如何在通知栏中创建文本?这是图像: 这是我的通知Android 如何在通知栏中创建文本?,android,text,statusbar,android-notifications,Android,Text,Statusbar,Android Notifications,正如你从这张图片中看到的,我想创建一个红色圆圈。如何在通知栏中创建文本?这是图像: 这是我的通知 notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.setOngoing(true); notificationBuilder.setContentTitle("Battery Stats Informations");
notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setOngoing(true);
notificationBuilder.setContentTitle("Battery Stats Informations");
notificationBuilder.setContentText("Carica residua: " +level+"%" + " " + "Temperatura: " +temperature+ "°C");
notificationBuilder.setTicker("Battery level " +level+ "%");
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setSmallIcon(R.drawable.icon_small_not).setWhen(System.currentTimeMillis());
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, 0);
notificationBuilder.setContentIntent(contentIntent);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification not=notificationBuilder.build();
mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,not);
感谢您有N个图标,每个图标对应于您要显示的不同“文本”,并在
通知.Builder
setSmallIcon()
调用中使用相应的图标
看,你看到的“文本”比“一个碰巧有数字的图像”要少。所以我必须做一些类似的事情:
if(level=100){notificationBuilder.setSmallIcon(R.drawable.icon\u small\u not)}if(level@David_D:That,或将它们组合成一个LevelListDrawable
,并使用setSmallIcon()的双参数版本)
将你的级别
作为第二个参数。我在3分钟前发布的方法是有效的。但是蓝色圆圈中的图像名称是什么?它不同吗?@David\u D:这就是setLargeIcon()
,如果愿意,您可以为其提供自定义渲染的位图。我如何创建位图图像?我只有一个png!