之前网上看了下自定义消息栏,通知栏,了解到了Notification这个控件,发现UC浏览器等都是这种类型,今天写个demo实现下,如图:

其中每个按钮都有不同的功能,代码如下:

package com.example.textwsjdemo;

import android.app.Activity;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.RemoteViews;

import android.widget.Toast;

public class MainActivity extends Activity {

private Button bt_hehe;

private NotificationManager notificationManager;

private Notification notification;

private int icon;

private CharSequence tickerText;

private long when;

RemoteViews contentView;

private Intent intent;

private PendingIntent pendingIntent;

private int notification_id = 0;

private MyBroadCast receiver;

private static String ACTION = "a";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

receiver = new MyBroadCast();

IntentFilter filter = new IntentFilter();

filter.addAction("a");

filter.addAction("b");

filter.addAction("c");

filter.addAction("d");

registerReceiver(receiver, filter);

initView();

initData();

}

private void initData() {

icon = R.drawable.ic_launcher; // 通知图标

tickerText = "Hello"; // 状态栏显示的通知文本提示

when = System.currentTimeMillis(); // 通知产生的时间,会在通知信息里显示

}

private void initView() {

bt_hehe = (Button) findViewById(R.id.bt_hehe);

bt_hehe.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

// 启动提示栏

createNotification();

}

});

}

private void createNotification() {

notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notification = new Notification();

notification.icon = icon;

notification.tickerText = tickerText;

notification.when = when;

/***

* 在这里我们用自定的view来显示Notification

*/

contentView = new RemoteViews(getPackageName(),

R.layout.notification_item);

contentView.setTextViewText(R.id.text11, "小说");

contentView.setTextViewText(R.id.text22, "视频");

contentView.setTextViewText(R.id.text33, "新闻");

contentView.setTextViewText(R.id.text44, "扯淡");

// contentView.setTextViewText(R.id.notificationPercent, "0%");

// contentView.setProgressBar(R.id.notificationProgress, 100, 0, false);

// //进度条

// contentView.setImageViewResource(R.id.image,R.drawable.more_advice);

// //加载图片

// contentView.setImageViewResource(R.id.image,R.drawable.more_attention);

// contentView.setImageViewResource(R.id.image,R.drawable.more_evaluate);

// contentView.setImageViewResource(R.id.image,R.drawable.more_about);

// contentView.setTextViewText(R.id.text,"Hello,this message is in a custom expanded view");

// //文本

notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻,不能滑动取消

//默认跳转的主界面

intent = new Intent(this, MainActivity.class);

intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

//自定义跳转

contentView.setOnClickPendingIntent(R.id.ll_11, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("a"), PendingIntent.FLAG_UPDATE_CURRENT));

contentView.setOnClickPendingIntent(R.id.ll_22, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("b"), PendingIntent.FLAG_UPDATE_CURRENT));

contentView.setOnClickPendingIntent(R.id.ll_33, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("c"), PendingIntent.FLAG_UPDATE_CURRENT));

contentView.setOnClickPendingIntent(R.id.ll_44, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("d"), PendingIntent.FLAG_UPDATE_CURRENT));

notification.contentView = contentView;

notification.contentIntent = pendingIntent;

notificationManager.notify(notification_id, notification);

}

// 取消通知

private void cancelNotification() {

notificationManager.cancelAll();

}

@Override

protected void onDestroy() {

cancelNotification();

unregisterReceiver(receiver);

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if ((keyCode == KeyEvent.KEYCODE_BACK)) {

System.out.println("按下了back键 onKeyDown()");

cancelNotification();

}

return super.onKeyDown(keyCode, event);

}

class MyBroadCast extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

if(intent.getAction().equals("a")){

Toast.makeText(MainActivity.this, "11111111111111",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText1.class));

}

if(intent.getAction().equals("b")){

Toast.makeText(MainActivity.this, "222222222222222",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText2.class));

}

if(intent.getAction().equals("c")){

Toast.makeText(MainActivity.this, "333333333333",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText3.class));

}

if(intent.getAction().equals("d")){

Toast.makeText(MainActivity.this, "4444444444444",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText4.class));

}

}

}

}

以下是一些属性的设置:

/*

* 添加声音

* notification.defaults |=Notification.DEFAULT_SOUND;

* 或者使用以下几种方式

* notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");

* notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");

* 如果想要让声音持续重复直到用户对通知做出反应,则可以在notification的flags字段增加"FLAG_INSISTENT"

* 如果notification的defaults字段包括了"DEFAULT_SOUND"属性,则这个属性将覆盖sound字段中定义的声音

*/

/*

* 添加振动

* notification.defaults |= Notification.DEFAULT_VIBRATE;

* 或者可以定义自己的振动模式:

* long[] vibrate = {0,100,200,300}; //0毫秒后开始振动,振动100毫秒后停止,再过200毫秒后再次振动300毫秒

* notification.vibrate = vibrate;

* long数组可以定义成想要的任何长度

* 如果notification的defaults字段包括了"DEFAULT_VIBRATE",则这个属性将覆盖vibrate字段中定义的振动

*/

/*

* 添加LED灯提醒

* notification.defaults |= Notification.DEFAULT_LIGHTS;

* 或者可以自己的LED提醒模式:

* notification.ledARGB = 0xff00ff00;

* notification.ledOnMS = 300; //亮的时间

* notification.ledOffMS = 1000; //灭的时间

* notification.flags |= Notification.FLAG_SHOW_LIGHTS;

*/

/*

* 更多的特征属性

* notification.flags |= FLAG_AUTO_CANCEL; //在通知栏上点击此通知后自动清除此通知

* notification.flags |= FLAG_INSISTENT; //重复发出声音,直到用户响应此通知

* notification.flags |= FLAG_ONGOING_EVENT; //将此通知放到通知栏的"Ongoing"即"正在运行"组中

* notification.flags |= FLAG_NO_CLEAR; //表明在点击了通知栏中的"清除通知"后,此通知不清除,

* //经常与FLAG_ONGOING_EVENT一起使用

* notification.number = 1; //number字段表示此通知代表的当前事件数量,它将覆盖在状态栏图标的顶部

* //如果要使用此字段,必须从1开始

* notification.iconLevel = ; //

最后附上源码:源码下载

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程圈。

android项目uc浏览器,Android项目仿UC浏览器和360手机卫士消息常驻栏(通知栏)相关推荐

  1. android 360状态栏显示,Android高仿UC浏览器和360手机卫士消息常驻栏(通知栏)

    之前网上看了下自定义消息栏,通知栏,了解到了Notification这个控件,发现UC浏览器等都是这种类型,今天写个demo实现下,如图: 其中每个按钮都有不同的功能,代码如下: package co ...

  2. android获取通知栏消息源代码,Android高仿UC浏览器和360手机卫士消息常驻栏(通知栏)(示例代码)...

    之前网上看了下自己定义消息栏,通知栏,了解到了Notification这个控件.发现UC浏览器等都是这样的类型,今天写个demo实现下.如图: 当中每一个button都有不同的功能.代码例如以下: p ...

  3. Android桌面悬浮窗效果实现,仿360手机卫士悬浮窗效果

    转载自:http://blog.csdn.net/guolin_blog/article/details/8689140 大家好,今天给大家带来一个仿360手机卫士悬浮窗效果的教程,在开始之前请允许我 ...

  4. 【android】仿360手机卫士的简易设计思路及源码

    笔者最近一直忙于满广州的跑,实习好难找好难找,博客也是有点久没去更新.仿360手机卫士的实现的目的更多的是出于对常用知识点的一个巩固吧,比较适合像我这种接触没多久的学习者在学习之余拿来练手保持写代码的 ...

  5. Android实现仿360手机卫士悬浮窗效果

    大家好,今天给大家带来一个仿360手机卫士悬浮窗效果的教程,在开始之前请允许我说几句不相干的废话. 不知不觉我发现自己接触Android已有近三个年头了,期间各种的成长少不了各位高手的帮助,总是有很多 ...

  6. android 360旋转动画,ANDROID——仿360手机卫士的旋转打分控件

    简介 灵感源自360手机卫,主要功能就是实现显示评分或等级的效果.并稍微改良了一下,有更好的实用性和扩展性. 因为主要用途就是显示"分数","评价",所以暂且叫 ...

  7. 高仿360手机卫士——Android源码

    高仿360手机卫士 高仿360手机卫士界面android源码,左右滑动效果,超炫. 下载地址:http://www.devstore.cn/code/info/1173.html 运行截图:    热 ...

  8. 仿360手机卫士首页[android平台]

    学习android几个月了,对android的UI开发部分一直不是很熟悉.于是最近拿360手机卫士首页来练手,做了个小demo,想与各位多多交流.效果图如下: (1)首页 (2)transformat ...

  9. android x86主动防御,360手机卫士首家实现X86架构手机主动防御

    联想昨天在北京正式发布Intel双核旗舰手机K900.X86架构的手机同时也得到广泛关注.记者刚刚获悉,360手机卫士最新版已率先完美支持英特尔 X86架构手机.据业内专家介绍,安全软件一些核心功能需 ...

最新文章

  1. ISME:根系招募特异型菌群增强植物对盐胁迫的抗性
  2. javascript动画系列第一篇——模拟拖拽
  3. FPGA之道(62)时空变换之空间换时间
  4. Elasticsearch源码分析—线程池(十一) ——就是从队列里处理请求
  5. 正则验证车牌号码,包括新能源车牌
  6. Kerberos策略的配置
  7. 百度OCR文字识别-Android安全校验
  8. 卷积神经网络爬虫实现新闻在线分类系统
  9. url中能出现的字符_网站URL配置4个技巧,轻松获得更多流量
  10. C语言——冒泡排序法
  11. JAVA-三目运算符返回值规则
  12. day28 java的集合(6)Properties和TreeSet
  13. 2个css特效冲突了怎么办_学生打扫卫生不积极怎么办?改变自己的观念,从2个方面影响学生...
  14. SpringBoot 核心原理分析
  15. IndexedQueueT——C#中的自定义队列
  16. 解决 fatal: Not a git repository (or any of the parent directories): .git 问题
  17. 今年因为疫情很多信用卡逾期,结果会怎么样?
  18. Jersey Restful WebService 接收 JSON 数组 对象
  19. Pascal数据结构与算法
  20. js中的instanceof运算符

热门文章

  1. MySQL8.0连接协议以及3306、33060、33062端口作用
  2. C#调用扫描仪(keda控件)
  3. 有没有可以同声传译的软件?同声传译app分享
  4. forEach如何遍历和删除自身
  5. rust wu马赛克_张大仙直播卡成马赛克,着装太丑耻辱下播,一复播让粉丝恋爱了...
  6. 请用Python语言写一个巨潮资讯网批量下载PDF的程序
  7. UI设计大作业 Axure原型 “美食分享制作”app高保真原型设计
  8. 数字的来源及数据思维的发展
  9. 2000坐标系xy坐标几位_什么是CGCS2000坐标系
  10. python是一种解释型编程语言_python是不是解释型语言