一、首先创建通知栏界面,先创建进度条背景颜色,创键progressbartiem.xml文件
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android>
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="0"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:startColor="#ff9d9e9d" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="0"
android:centerY="0.75"
android:endColor="#80999999"
android:startColor="#80999999" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="0"
android:endColor="#801cdca4"
android:startColor="#801cdca4" />
</shape>
</clip>
</item>
</layer-list>
二,创建通知栏界面
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical" >
<ImageView
android:id="@+id/custom_progress_icon"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_margin="5dip"
android:padding="5dip"
android:src="@mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toRightOf="@id/custom_progress_icon" >
<TextView
android:id="@+id/tv_custom_progress_title"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textColor="#222222"
android:text="妈妈安心-家长"
android:textSize="15dp" />
<TextView
android:id="@+id/tv_custom_progress_status"
style="@style/NotificationContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_custom_progress_title"
android:layout_centerHorizontal="true"
android:layout_marginRight="10dp"
android:text="妈妈安心-家长"
android:visibility="gone"
android:textSize="12dp" />
<ProgressBar
android:id="@+id/custom_progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="80"
android:progressDrawable="@drawable/progressbartiem"
android:layout_below="@id/tv_custom_progress_status" />
</RelativeLayout>
</RelativeLayout>
三、创建通知栏和更新进度条
/**
* 创建通知栏
*/
private void createCreateProgressNotify(String status){
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification();
notification.icon = R.mipmap.ic_launcher;
// 这个参数是通知提示闪出来的值.
notification.tickerText = "妈妈安心-家长";
if(mRemoteViews == null){
mRemoteViews = new RemoteViews(getPackageName(), R.layout.view_custom_progress);
mRemoteViews.setImageViewResource(R.id.custom_progress_icon, R.mipmap.ic_launcher);
mRemoteViews.setTextViewText(R.id.tv_custom_progress_title, "妈妈安心-家长"+status);
mRemoteViews.setProgressBar(R.id.custom_progressbar, 100, 1, false);
}
notification.contentView = mRemoteViews;
notificationManager.notify(notifyId, notification);
}
/**
* 更新通知栏
*/
private void updateProgressNotify(int progress){
notification.contentView.setProgressBar(R.id.custom_progressbar, 100, progress, false);
notificationManager.notify(notifyId, notification);
if(progress>=99){
notificationManager.cancel(notifyId);
}
}