首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何控制通知中的进度条(没有Notification.Builder)?

如何控制通知中的进度条(没有Notification.Builder)?
EN

Stack Overflow用户
提问于 2013-08-06 18:15:27
回答 1查看 888关注 0票数 0

由于某种原因,我无法在我的代码中使用android-support-library。为了执行与Android4.0风格匹配的通知,我写了以下代码:

代码语言:javascript
运行
复制
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中。

我发现了另一种方法,那就是

代码语言:javascript
运行
复制
notification.setProgressBar(int viewId, int max, int progress, boolean indeterminate)

但另一个问题是,它需要一个包含进度条的自定义通知布局。如果我使用自定义布局,它将不会与android 4.0风格相匹配。

我现在能做什么?请帮帮我,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2015-05-12 10:33:16

我通过使用来自安卓源代码here的自定义布局解决了这个问题,所以它看起来像是一个系统通知。希望这能帮助到其他人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18077312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档