往SystemUI添加进度条

1、定义一个进度条的布局文件
    res/layout/notificat_progress.xml
2、用RemoteViews显示布局
    RemoteViews view = new RemoteViews(getPackageName(), R.layout.notificat_progress);
3、用Notification发布通知
    Notification    notification =new Notification     (通知图标,通知信息,0);
4、实际代码
    RemoteViews view = null;
    Notification notification;
    Intent intent= new Intent();;
    PendingIntent pendingIntent;
    pendingIntent = PendingIntent.getActivity(Gallery.this, 0, intent, 0);
    notification = new Notification (R.drawable.download_current,getResources().getString(R.string.download_massege),0);
    view = new RemoteViews(getPackageName(), R.layout.notificat_progress);
    view.setProgressBar(R.id.progress, 100, 0, false);//设置进度条
    view.setTextViewText(R.id.percent,   0 + "%");     //设置显示百分比
    notification.defaults = Notification.FLAG_ONLY_ALERT_ONCE;
    notification.icon = R.drawable.download_current;//状态栏显示图标
    notification.contentView = view;
    notification.contentIntent = pendingIntent;
    notificationManager.notify(0, notification); //发布通知

你可能感兴趣的:(往SystemUI添加进度条)