Android 通知栏进度更新条

一、首先创建通知栏界面,先创建进度条背景颜色,创键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);
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值