<ProgressBar
android:id="@+id/custom_progressbar"
style="@style/StyleProgressBarMini"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_progressbar_bg"
android:max="100"
android:progress="0" />
<!-- progressbar -->
<style name="StyleProgressBarMini" parent="@android:style/Widget.ProgressBar.Horizontal">
<item name="android:maxHeight">20dip</item>
<item name="android:minHeight">5dip</item>
<item name="android:indeterminateOnly">false</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
<item name="android:progressDrawable">@drawable/shape_progressbar_mini</item>
</style>
//@drawable/shape_progressbar_mini
<?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="270"
android:centerY="0.75"
android:endColor="#FFFFFF"
android:startColor="#FFFFFF" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="0dip" />
<gradient
android:angle="270"
android:centerY="0.75"
android:endColor="#df0024"
android:startColor="#df0024" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerY="0.75"
android:endColor="@color/top_bar"
android:startColor="@color/top_bar" />
</shape>
</clip>
</item>
</layer-list>

//在通知栏中显示ProgressBar
/**
* 初始化要用到的系统服务
*/
private void initService() {
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
/**
* 显示状态栏进度条
*/
public void showCustomProgressNotify() {
initService();
mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.custom_notification_progress);
mRemoteViews.setImageViewResource(R.id.custom_progress_icon, R.drawable.ic_launcher);
Intent intent = new Intent(DOWNLOADFAILED_ACTION);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
mRemoteViews.setOnClickPendingIntent(R.layout.custom_notification_progress, pendingIntent);
PendingIntent pi = getDefalutIntent(0);
mNotification = new Notification.Builder(context).setAutoCancel(true).setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pi).build();
mNotification.contentView = mRemoteViews;
mRemoteViews.setProgressBar(R.id.custom_progressbar, 100, 0, false);
mNotificationManager.notify(NOTIFYID, mNotification);
}
/**
* 下载更新状态栏进度条
*/
Handler downloadHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == DOWNLOADING ||msg.what == DOWNLOADSUCCESS) {
mRemoteViews.setTextViewText(R.id.tv_custom_progress_title, context.getString(R.string.down_start));
mRemoteViews.setProgressBar(R.id.custom_progressbar, 100, progress, false);
mRemoteViews.setTextViewText(R.id.tv_custom_progress_percent, String.valueOf(progress));
if (progress == 100) {
mRemoteViews.setTextViewText(R.id.tv_custom_progress_title, context.getString(R.string.down_success));
}
mNotification.contentView = mRemoteViews;
mNotificationManager.notify(0, mNotification);
}else if (msg.what == DOWNLOADFAILED) {
mRemoteViews.setTextViewText(R.id.tv_custom_progress_title, context.getString(R.string.down_failed));
mRemoteViews.setProgressBar(R.layout.custom_notification_progress, 100, progress, false);
mNotification.contentView = mRemoteViews;
mNotificationManager.notify(0, mNotification);
}
super.handleMessage(msg);
}
};
这个由于是从项目中提取的,所以有些是缺失的,我只是记录一下到时候能记起来,基本的方法都在上面了
ProgressBar自定义样式
最新推荐文章于 2024-05-07 18:00:19 发布
