1

我想在 android 的状态栏上显示数字作为文本。我已经设置了图标,但我想设置动态的数字。有没有可能做到这一点。

//Create the Notification
Notification notification = new Notification(android.R.drawable.stat_sys_warning, "Battery Indicator", System.currentTimeMillis());
//Create a PendingIntent to do something when the user clicks on the Notification
//Normally this would be something in your own app
Intent intent = new Intent();
intent.setClass(getApplicationContext(), BatteryIndicator.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);

//Add the detail to the Notification
notification.setLatestEventInfo(getApplicationContext(),"Battery Indicator", "Charge level: " + batteryRemaining , pi);

//Display the Notification
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notification); 
4

2 回答 2

0

Android ProgressBar(如果你指的是这个类)不支持任何setText或类似的。我建议创建一个自定义组件覆盖onDraw(Canvas). 您可以打电话super.onDraw来完成大部分工作,然后使用Canvas.drawText在中心绘制数字(使用View.getWidthgetHeight找到该中心的位置)。

于 2013-01-23T08:10:33.297 回答
0

使用 notification.number=value;

于 2013-01-23T08:58:22.517 回答