android-带进度条的系统通知栏消息
效果图:
主界面只有一个按钮就不上文件了
通知栏显示所用到的布局文件content_view.xml
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#00000000"
- android:orientation="vertical"
- android:padding="5dp">
- <ImageView
- android:id="@+id/content_view_image"
- android:layout_width="25dp"
- android:layout_height="25dp"
- android:src="@drawable/logo"
- />
- <TextView
- android:id="@+id/content_view_text1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="0%"
- android:textColor="#000000"
- android:layout_toRightOf="@id/content_view_image"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="5dp"
- android:layout_marginLeft="15dp"
- />
- <ProgressBar
- android:id="@+id/content_view_progress"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- style="@android:style/Widget.ProgressBar.Horizontal"
- android:max="100"
- android:layout_below="@id/content_view_image"
- android:layout_marginTop="4dp"
- />
- </RelativeLayout>
主运行类:
- package yyy.testandroid4;
- import java.util.Timer;
- import java.util.TimerTask;
- import android.app.Activity;
- import android.app.AlertDialog.Builder;
- import android.app.Notification;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.pm.PackageManager.NameNotFoundException;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.RemoteViews;
- import android.widget.Toast;
- public class TestAndroid4Activity extends Activity {
- private Handler handler = new Handler(){
- @Override
- public void handleMessage(Message msg) {
- // TODO Auto-generated method stub
- super.handleMessage(msg);
- switch (msg.what) {
- case 0:
- notif.contentView.setTextViewText(R.id.content_view_text1, len+"%");
- notif.contentView.setProgressBar(R.id.content_view_progress, 100, len, false);
- manager.notify(0, notif);
- break;
- case 1:
- Toast.makeText(TestAndroid4Activity.this, "下载完成", 0).show();
- break;
- default:
- break;
- }
- }
- };
- private Button update,cancel;
- private int localVersion,serverVersion;
- private int len;
- private NotificationManager manager;
- private Notification notif;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- update = (Button) findViewById(R.id.update);
- update.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- //点击通知栏后打开的activity
- Intent intent = new Intent(TestAndroid4Activity.this,OtherActivity.class);
- PendingIntent pIntent = PendingIntent.getActivity(TestAndroid4Activity.this, 0, intent, 0);
- manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notif = new Notification();
- notif.icon = R.drawable.logo;
- notif.tickerText = "新通知";
- //通知栏显示所用到的布局文件
- notif.contentView = new RemoteViews(getPackageName(), R.layout.content_view);
- notif.contentIntent = pIntent;
- manager.notify(0, notif);
- new DownLoadThread().start();
- }
- });
- }
- }
- private class DownLoadThread extends Thread{
- private Timer timer = new Timer();
- @Override
- public void run() {
- // TODO Auto-generated method stub
- super.run();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- Message msg = new Message();
- msg.what = 0;
- msg.obj = len;
- handler.sendMessage(msg);
- if(len == 100){
- timer.cancel();
- handler.sendEmptyMessage(1);
- }
- }
- }, 0, 1000);
- len = 0;
- try {
- while(len < 100){
- len++;
- Thread.sleep(1000);
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
android-带进度条的系统通知栏消息的更多相关文章
- 025 Android 带进度条的对话框(ProgressDialog)
1.ProgressDialog介绍 ProgressDialog可以在当前界面弹出一个置顶于所有界面元素的对话框,同样具有屏蔽其他控件的交互能力,用于提示用户当前操作正在运行,让用户等待: 2.应用 ...
- Android带进度条的文件上传,使用AsyncTask异步任务
最近项目中要做一个带进度条的上传文件的功能,学习了AsyncTask,使用起来比较方便,将几个方法实现就行,另外做了一个很简单的demo,希望能对大家有帮助,在程序中设好文件路径和服务器IP即可. A ...
- 高仿手机QQ音乐之——Android带进度条的开关
最新版的手机QQ音乐体验确实不错,发现首页播放按钮能够显示歌曲当前进度条.认为挺有新意.效果例如以下: 自己琢磨了下.能够用自己定义组件来实现,试着做了一下.效果例如以下: 整理了下思路.大概设计流程 ...
- Android更新带进度条的通知栏
在网上查询了下.Android版本号更新通知栏带进度条,醉了,基本都是复制过来.有的代码不全,连源代码下载都没有.有下载也须要积分,还不能用,真黑心啊!!之前自己也写过自己定义通知栏Notificat ...
- Android -- 自定义带进度条的按钮
1. 实现了一个带进度条的按钮,完成后显示提示信息,并设置按钮为不可再次被点击
- [Delphi]带进度条的ListView
带进度条的ListView unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, C ...
- android多线程进度条
多线程实现更新android进度条. 实例教程,详细信息我已经注释 android多线程进度条 01package com.shougao.hello; 02 03import android ...
- 自定义带进度条的WebView , 增加获取web标题和url 回掉
1.自定义ProgressWebView package com.app.android05; import android.content.Context; import android.graph ...
- android 自定义进度条颜色
android 自定义进度条颜色 先看图 基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程! 这个没法了只能看源码了,还好下载了源码, sources\b ...
随机推荐
- UITableViewCell性能优化
5.UITableViewCell性能优化 > 定义一个循环利用标识 static NSString *ID = @"C1"; > 从缓存池中取出可循环利用的cell ...
- ArcGIS学习推荐基础教程摘录
###########-------------------摘录一--------------------------########### ***************************** ...
- VC维的物理意义
vc约等于可调节参数的个数 来自为知笔记(Wiz)
- 如何交换a和b两个整数的值,不用额外空间
这个题貌似完全颠覆一般的Logic:交换两个整数需要一个额外的空间用于保存: t = b; b = a; a = t; 粗看上去似乎没有办法,但是仔细想一下,既然不能用额外的空间,那么能用的方法就只 ...
- [Linux] 修改主机名(hostname)
在Linux命令行下输入hostname,查看当前主机名,如果想修改它,直接在hostname后面加上新主机名即可(注:以下操作都需要root用户执行),如: # hostname newhostna ...
- 开源DirectShow分析器和解码器: LAV Filter
LAV Filter 是一款开源的DirectShow视频分离和解码软件,他的分离器LAVSplitter封装了FFMPEG中的libavformat,解码器LAVAudio和LAVVideo则封装了 ...
- 关于关注和取消关注的nodejs写法
本例子的关注和取消关注,是通过ajax的方法实现的:nodejs后台写好api接口:响应前台的ajax 先看ajax的代码实现: // 用户关注标签 function subscribe(uid, t ...
- Ubuntu12.04下eclipse提示框黑色背景色的修改方法
eclipse提示框的背景颜色使用的是系统的提示框颜色配置,在windows下为黄色,但在Ubuntu12.04(gnome)下却是黑色,造成提示内容很难看清. 在eclipse中我们是无法修改这个颜 ...
- 项目积累——Blockingqueue,ConcurrentLinkedQueue,Executors
背景 通过做以下一个小的接口系统gate,了解一下mina和java并发包里的东西.A系统为javaweb项目,B为C语言项目,gate是本篇须要完毕的系统. 需求 1. A为集群系统,并发较高,会批 ...
- jquery单页网站导航插件One Page Nav
这是一个轻量级的jQuery的单页网站导航插件.增加了单击后平滑滚动导航和当你浏览不同的部分时自动选择正确的导航项. changeHash: false, 改变当用户单击导航,就改变changeHas ...