更新进度条在通知区域 [英] Updating the Progress Bar in the Notification Area
本文介绍了更新进度条在通知区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有几个线程已经就如何使自定义布局在通知栏。问题是我必须失去了一些东西简单。
There are several threads already on how to make custom layouts in the notification bar. The problem is I must be missing something simple.
我有一个custom_notification_layout.xml
I have a custom_notification_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dip"
>
<TextView android:id="@+id/text"
android:text="Uploading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:max="0"
android:progress="0"
android:layout_marginLeft="10dip"
android:id="@+id/progressBar"
/>
</LinearLayout>
我也有一些测试code创建的通知,其工作方式,并显示进度条。
I also have some test code that creates the notification, which works and shows the progress bar.
NotificationManager mManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, title, System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification_layout);
contentView.setProgressBar(R.id.progressBar, 10, 0, false);
contentView.setTextViewText(R.id.text, text);
notification.contentView = contentView;
Intent notificationIntent = new Intent(context, NotificationHandler.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
mManager.notify(APPID, notification);
最后,我尝试更新的进度条,这是行不通的。
Finally I try to update the progress bar, which doesn't work.
contentView.setProgressBar(R.id.progressBar, 10, 5, false);
什么是秘密实际更新通知?
What is the secret to actually updating the notification?
推荐答案
您应该添加以下两行:
// update the notification object
notification.contentView.setProgressBar(R.id.progressBar, 10, 5, false);
// notify the notification manager on the update.
mManager.notify(APPID, notification);
这篇关于更新进度条在通知区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文