由于某种原因,我无法在我的代码中使用android-support-library。为了执行与Android4.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风格相匹配。
我现在能做什么?请帮帮我,谢谢!
发布于 2015-05-12 10:33:16
我通过使用来自安卓源代码here的自定义布局解决了这个问题,所以它看起来像是一个系统通知。希望这能帮助到其他人。
https://stackoverflow.com/questions/18077312
复制相似问题