出于某种原因,我没有在我的代码中使用android-support-library。为了执行符合Android 4.0风格的通知,我写这个:
private void noti() {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence text = "Notification Text";
CharSequence contentTitle = "Notification Title";
CharSequence contentText = "Sample notification text.";
long when = System.currentTimeMillis();
Intent intent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(icon,text,when);
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
notificationManager.notify(1, notification);
}
如何控制进度条呢? developer.google.com中的方式是使用Notification.Builder
,但Builder位于android-support-library中。
我发现另一种方法是
notification.setProgressBar(int viewId, int max, int progress, boolean indeterminate)
但另一个问题是它需要一个包含进度条的自定义通知布局。如果我使用自定义布局,它将不符合android 4.0风格。
我现在能做什么?请帮帮我,谢谢!