刷新通知栏中的进度栏
我想在通知栏中放置一个进度栏。这个想法显示了程序将文件上传到服务器时的进度条。其他一切都可以,但我无法弄清楚如何刷新通知中的进度条。有人知道任何模式可以玩吗?我的意思是,我应该在哪里刷新进度条,在服务或活动等等。刷新通知栏中的进度栏
我不知道你的代码是什么样子,所以我不知道你需要修改的,布提做了一些通过文件搜索。我在Notifications,ProgressBars和RemoteViews上发现了一些东西。
具体来说,在RemoveView中,您可以更新进度栏。因此,结合一些示例代码中的每一个环节,我得到的是这样的:
public class MyActivity extends Activity {
private static final int PROGRESS = 0x1;
private static final int MAX_PROGRESS = 100;
private int mProgressStatus = 0;
private Handler mHandler = new Handler();
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
//define Notification
//...
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, mProgressStatus, false);
notification.contentView = contentView;
// Start file upload in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < MAX_PROGRESS) {
mProgressStatus = doWork();
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, mProgressStatus, false);
}
});
}
}
}).start();
}
}
您是否必须在自定义xml布局中定义进度条?或者将RemoteViews.setProgressBar()处理。我问的原因是因为http://developer.android.com/reference/android/widget/RemoteViews.html#setProgressBar(int,int,boolean)他们说给“的文本应该改变的视图的ID “。 – Pzanno 2011-02-16 02:07:46
@Pzanno - 我想知道完全一样的东西(因此+1)。我发现你必须在自定义xml布局中定义你自己的进度条。 – ArtOfWarfare 2012-12-07 16:54:19
很好的例子...我也在我的客户视图中使用progressbar,但是...它挂起我的系统我不知道为什么...一切顺利,默认通知进度条 – 2016-08-05 09:34:40
可以在通知使用自定义视图:
https://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView
事实证明,这个答案是唯一对我有用的答案,但是有这么多的信息可供您阅读,以至于您无法真正了解把它放在一个简洁的答案。链接是官方文档,如果更改只是更新链接。 – 2015-05-31 22:18:04
要删除进度从远程视窗使用下面的代码: -
remoteViews.setViewVisibility(R.id.progressBar, View.INVISIBLE);
您还可以使用View.GONE
但将使android填充空白空间。
我不知道这是否可能。你有没有用GIF动画试过? – Macarse 2010-04-22 12:41:05
还没有,但我需要实时显示上传进度,所以我需要更新进度条。我认为如果你只显示“加载”消息,那么使用动画gif是有效的。无论如何感谢您的时间。 – ahmontero 2010-04-22 13:42:32
我确定它可能。市场应用程序在通知栏中下载和安装应用程序时显示进度条... – seanmonstar 2010-04-27 20:59:48