android 在通知栏显示进度条,android进度条,[Java]代码 //得
分享于 点击 17697 次 点评:182
android 在通知栏显示进度条,android进度条,[Java]代码 //得
[Java]代码
//得到通知管理类 notiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); //创建一个通知,icon为状态栏显示图片,第二参数为提示信息 notification = new Notification(R.drawable.icon, getResources().getString(R.string.start_update_app),System.currentTimeMillis()); //RemoteViews 作用为显示通知栏layout问及爱你 notification.contentView = new RemoteViews(getPackageName(),R.layout.notification_update_progressbar); Intent notificationIntent = new Intent(this,APKUpdateService.class); PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0); notification.contentIntent = contentIntent; //发送一个通知到通知栏 notiManager.notify(10, notification);
xml配置:
<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">" <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/mg_icon" /> <RelativeLayout android:paddingTop="20dip" android:layout_width="match_parent" android:layout_height="match_parent" > <ProgressBar android:id="@+id/pb" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:indeterminate="false" /> <TextView android:id="@+id/down_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="16sp" android:textColor="#000000" android:text="@string/downloading" /> </RelativeLayout></LinearLayout>
[Java]代码
//得到通知管理类 notiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); //创建一个通知,icon为状态栏显示图片,第二参数为提示信息 notification = new Notification(R.drawable.icon, getResources().getString(R.string.start_update_app),System.currentTimeMillis()); //RemoteViews 作用为显示通知栏layout问及爱你 notification.contentView = new RemoteViews(getPackageName(),R.layout.notification_update_progressbar); Intent notificationIntent = new Intent(this,APKUpdateService.class); PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0); notification.contentIntent = contentIntent; //发送一个通知到通知栏 notiManager.notify(10, notification);
<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">" <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/mg_icon" /> <RelativeLayout android:paddingTop="20dip" android:layout_width="match_parent" android:layout_height="match_parent" > <ProgressBar android:id="@+id/pb" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:indeterminate="false" /> <TextView android:id="@+id/down_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="16sp" android:textColor="#000000" android:text="@string/downloading" /> </RelativeLayout></LinearLayout>
用户点评