创建定制化的通知布局
默认情况下,在通知窗口显示的通知包括标题和消息文本。这两项内容使用通过setLatestEventInfo()方法的contentTitle和contentText参数来定义的。但是,你也能够使用RemoteViews类给通知定义一个定制化的布局。如图3所示就是一个定制的通知布局的例子。它看上去与默认的通知类似,但是实际上它是用一个定制的XML布局来创建的。
图3.带有定制化布局的通知。
要给通知创建自己的布局,就要实例化一个RemoteViews对象,用它来填充一个定制的布局文件,然后把RemoteViews对象传递给通知的contentView属性字段。
下面用一个例子来更好的理解如何创建定制化的通知:
1. 给通知创建XML布局,如以下在custom_notification.xml文件中定义的通知布局:
<RelativeLayout
xmlns:android="doc.guandang.net; android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp" >
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
style="@style/NotificationTitle" />
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:layout_below="@id/title"
style="@style/NotificationText" />
</RelativeLayout>
我们注意到,两个TextView元素都包含了style属性,给定制的通知中的文本使用样式资源是至关重要的,因为通知的背景色在不同设备和平台版本中会有所差异。从Android2.3(API级别9

)开始,系统给默认的通知布局所使用的文本定义了样式,这样
【Android开发API】用户界面 - 状态通知 - Status Notifications_计算机软件及应用_IT/计算机_专业资料。 eoe 移动开发者社区 www.eoe.cn 负责?:Kobehonghai 原文...
【Android开发API】用户界面 - Toast通知 - Toast Notifications_计算机软件及应用_IT/计算机_专业资料。eoe 移动开发者社区 www.eoe.cn 原文链接:http://...
【Android开发Design】通知 - Notifications 1_制度/规范_工作范文_应用文书。... 要让产品有好的用户体验... 能让UI设计显得更简约的... 马桶到删除:从...
android用户界面程序设计_IT/计算机_专业资料。淮海工学院计算机工程学院 实验...(可参考文档中 Dev Guide 的帮助主题 Toast Notifications 中的内容) 三、实验...
这个章节描述怎么实现一个基本的 Android 界面.它涉及构建屏幕基本元素,怎么在 xml(定义文件)内定义屏幕, 用你的代码生成, 在不同任务你需要操作你的用户接口. ...
Android用户界面框架 ? MVC模型 ? ? MVC模型中的控制器能够接受并响应程序的外部动作, 如按键动作或触摸屏动作等 控制器使用队列处理外部动作,每个外部动作作为一...
图形用户界面设计 目标学员: 学习目标: Android初级开发者用户界面设计原则 用户界面设计核心概念 对话框 菜单 通知 课程时长: 4学时,180分钟 课程目录 1 2 3 4...
9.Android用户界面UI元素之对话框(Dialog)和通知(Notification)_IT/计算机_专业资料。Android开发教程Softeem Consultancy Service Android用户界面(UI)组件 用户界面( ...
? ? ? ? User Interface(用户界面) View Hierarchy(视图层次) How Android ...(风格与主题) Notifications(通知) ActionBar(活动栏) Drag and Drop(拖拽) ...
热门文档