一、RemoteViews简介

作用:跨进程更新界面                         使用场景:通知栏、桌面小部件

二、在通知栏上的应用

原理:通过RemoteViews加载布局,通过remoteViews的set方法,载入View动态改变布局

(一)、Notifaction的使用:Notification的使用

(二)、利用RemoteView来自定义布局

步骤①、创建layout布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/show_linear"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/show_iv_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/ic_launcher"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/show_tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World"/>
<TextView
android:id="@+id/show_tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I am a super man"/>
</LinearLayout>
</LinearLayout>

notification_show

步骤②、利用RemoteViews动态修改布局

 Intent intent = new Intent(this,OtherActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
//利用Notification.Builder创建Notification
Notification.Builder notification = new Notification.Builder(this);
notification.setAutoCancel(true);
notification.setSmallIcon(R.mipmap.ic_launcher);
notification.setContentTitle("Hello World");
notification.setContentText("I am a ET");
notification.setContentIntent(pendingIntent);
/*利用RemoteViews动态修改layout的内容*/
//通过包名,和自定义的layout创建RemoteViews
RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.notification_show);
//修改View的内容
remoteViews.setImageViewResource(R.id.show_iv_icon,R.mipmap.ic_launcher);
remoteViews.setTextViewText(R.id.show_tv_title,"This is fine day");
remoteViews.setTextViewText(R.id.show_tv_content,"Do you want to go with me");
//对RemoteViews设置跳转
remoteViews.setOnClickPendingIntent(R.id.show_linear,pendingIntent);
//将notification的View设置为RemoteViews
notification.setContent(remoteViews);
notification.setContentIntent(pendingIntent);
//配置完成后,将builder转化为Notification
Notification notification1 = notification.getNotification();
//放入Notification管理器中
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0,notification1);

问:为什么更新View需要用到RemoteViews类(稍后讲解)

为什么需要用到PendingIntent。(说明Intent中所包含的意图必须由用户触发)

三、RemoteViews在桌面小部件上的应用(放弃,以后再说)

AppWidgetProvider是Android用于实现桌面小部件的类,本质上是一个广播(BroadcastRecevier)

步骤:①、定义小部件(在res/layout/下新建一个XML文件)  自 定 义

②、定义小部件配置信息(res/xml/下新建一个xml文件)

RemoteViews的理解和使用的更多相关文章

  1. Android开发艺术探索第五章——理解RemoteViews

    Android开发艺术探索第五章--理解RemoteViews 这门课的重心在于RemoteViews,RemoteViews可以理解为一种远程的View,其实他和远程的Service是一样的,Rem ...

  2. Android自定义Notification并没有那么简单

    背景 最近需要实现一个自定义Notification的功能.网上找了找代码,解决方案就是通过RemoteViews来实现.但是在实现过程中遇到不少问题,网上也没有很好的文章描述这些问题,所以在这里做个 ...

  3. Android开发艺术探索》读书笔记 (5) 第5章 理解RemoteViews

    第5章 理解RemoteViews 5.1 RemoteViews的应用 (1)RemoteViews表示的是一个view结构,它可以在其他进程中显示.由于它在其他进程中显示,为了能够更新它的界面,R ...

  4. 完全理解Android中的RemoteViews

    一.什么是RemoteViews RemoteViews翻译过来就是远程视图.顾名思义,RemoteViews不是当前进程的View,是属于SystemServer进程.应用程序与RemoteView ...

  5. 第五章:理解RemoteViews

    RemoteView应该是一种远程View,表示的是一个View结构,他可以在其它进程中显示. 在android中使用场景有两种:通知栏和桌面小部件 5.1 RemoteView的应用 5.1.1 R ...

  6. Notification NotificationManager RemoteViews PendingIntent

    Notification和NotificationManager :可以用来实现可视化的消息通知等,比如:下载进度显示,消息显示,广播的内容等 RemoteViews :用于创建自定义的Notific ...

  7. Android RemoteViews 11问11答

    1.什么是RemoteView? 答:其实就是一种特殊的view结构,这种view 能够跨进程传输.并且这种remoteview 还提供了一些方法 可以跨进程更新界面.具体在android里面 一个是 ...

  8. Android 之窗口小部件高级篇--App Widget 之 RemoteViews - 跨到对岸去

    在之前的一篇博文( Android 之窗口小部件详解--App Widge t)中,已经介绍了App Widget的基本用法和简单实例.这篇主要讲解 App Widget 的高级内容,即通过 Remo ...

  9. Android 之窗口小部件高级篇--App Widget 之 RemoteViews

    Android 之窗口小部件高级篇--App Widget 之 RemoteViews 在之前的一篇博文(Android 之窗口小部件详解--App Widget)中,已经介绍了App Widget的 ...

随机推荐

  1. SSH 概念及使用详解

    注意:转载请注明出处:http://www.programfish.com/blog/?p=124 SSH 基本概念 SSH 英文全称是secure shell,字面意思:安全的shell. SSH协 ...

  2. typedef函数指针那些事

    首先来介绍下函数指针: 函数指针是指向函数的指针变量,即本质是一个指针变量. int (*f) (int x); /* 声明一个函数指针 */ f=func; /* 将func函数的首地址赋给指针f ...

  3. 【转】WPF - 第三方控件

    WPF - 第三方控件 目前第三方控件在网上形成巨大的共享资源,其中包括收费的也有免费的,有开源的也有不开源的,合理的使用第三方控件将使项目组的工作事半功倍.比如项目中有些复杂的业务逻辑.有些绚丽的效 ...

  4. JavaSctipr 兼容、技巧、牛角尖

    关于JavaSctipt的兼容性,最懒的办法就是用jQuery的工具函数.尽量不要用那些什么ECMAScript之类的函数,因为很多浏览器都会报找不到函数的错误.下面列出一些在开发过程中碰到过的jav ...

  5. Asp.net 处理程序(第五篇)

    HttpApplication有19个标准事件,当到达第8个事件PostMapRequestHandler触发的时候,标志着已经获取到了处理请求的处理程序对象,在第11个事件PreRequestHan ...

  6. C# Process类_进程_应用程序域与上下文之间的关系

    进程(Process)是Windows系统中的一个基本概念,它包含着一个运行程序所需要的资源.进程之间是相对独立的,一个进程无法直接访问另一个进程的数据(除非分布式),一个进程运行的失败也不会影响其他 ...

  7. 用于下载AD官网登录账号:User name: fuxin918@fuxin918.com Passeword: s6c0W1w8

    用于下载AD官网登录账号:User name: fuxin918@fuxin918.com Passeword:  s6c0W1w8

  8. jmp指令

    jmp指令可以是直接跳转也可以是间接跳转. 直接跳转ATT   jmp  Lable 无条件跳转,一般相对于PC 间接跳转ATT jmp *adr 无条件跳转,常见于switc语句中

  9. 剑指offer-面试题20.顺时针打印矩阵

    题目:输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字.例如: 输入一个矩阵如下: 则依次打印出数字:1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10 这道题的 ...

  10. hdu 2896 病毒侵袭_ac自动机

    题意:略 思路:套用ac自动机模板 #include <iostream> #include<cstdio> #include<cstring> using nam ...