设为首页 加入收藏

TOP

Android带进度条的通知栏(源码)
2014-11-24 12:42:38 来源: 作者: 【 】 浏览:2
Tags:Android 进度 通知 源码

相关文件下载在Linux公社的1号FTP服务器里,下载地址:


密码:www.muu.cc


在 2011年LinuxIDC.com\10月\10月\Android带进度条的通知栏源码


下载方法见 http://www.linuxidc.net/thread-1187-1-1.html


示例代码:


package com.hemowolf;


import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RemoteViews;



public class main extends Activity implements OnClickListener{
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
_thread.interrupt();
nm.cancel(NF_ID);
}


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.btnShow).setOnClickListener(this);
findViewById(R.id.btnCancel).setOnClickListener(this);


nf =new Notification(R.drawable.icon,"带进度条的提醒",System.currentTimeMillis()) ;
nf.icon = R.drawable.icon;

nf.contentView= new RemoteViews(this.getPackageName(),R.layout.notification);
nf.contentView.setProgressBar(R.id.ProgressBar01, 100, 0, false);
nf.contentIntent=PendingIntent.getActivity( this, 0, new Intent(this,remoteview.class) ,0);

nm = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
}

public void onClick(View v) {
switch(v.getId()){
case R.id.btnShow:


nm.notify(NF_ID, nf);

_thread = new Thread ( new Runnable(){
public void run() {
while ( !Thread.currentThread().isInterrupted()){
_handler.sendMessage(Message.obtain());
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
break ;
}
}
}
});
_thread.start();
break;
case R.id.btnCancel:
_thread.interrupt();
nm.cancel(NF_ID);
break;

}
}

private Handler _handler =new Handler(){
public void handleMessage(Message msg) {
super.handleMessage(msg);
_progress +=10;
if (_progress>=100) _progress=0;
nf.contentView.setProgressBar(R.id.ProgressBar01, 100, _progress, false);
nm.notify(NF_ID, nf);
}
};


private final int NF_ID=1111;
private Notification nf ;
private NotificationManager nm ;
private int _progress=0;
private Thread _thread ;
}



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android在屏幕任意点移动图片(附.. 下一篇在Android的Listview中显示多种视..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)