Notification基础详解三(宽视图布局通知)
Notification是在你的应用常规界面之外展示的消息。当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏。要查看消息的详情需要进入通知抽屉(notificationdrawer)中查看。通知栏和通知抽屉
(notificationdrawer)都是系统层面控制的,你可以随时查看,不限制于app。
Notification 的设计:
作为Android UI中很重要的组成部分,notification拥有专属于自己的设计准则。
Notification的界面元素在通知抽屉中的notification有两种显示方式,取决于你的android版本以及notification drawer的状态:
(1)普通视图
这种风格是notification drawer的标准显示方式。
(2)宽视图
指你的notification被展开的时候会显示更大的视图,这种风格是android4.1之后才有的新特性。
下面将详细介绍宽视图:
只有当notification被展开的时候这种宽视图的notification才会出现,通过手势操作可以展开一个普通的notification(部分定制系统不可以,会直接显示宽视图)。这种风格的notification从android4.1以后才开始支持。下面的截图展示了inbox风格的notification:
你应该注意到了这种notification其实跟普通的没多大差别,
唯一的区别在于数字7-详情区域。
详情区域根据用途可有多种风格:
1.NotificationCompat.BigPictureStyle 大图片风格:详情区域包含一个256dp高度的位图
2.NotificationCompat.BigTextStyle 大文字风格:显示一个大的文字块
3.NotificationCompat.InboxStyle 收件箱风格:显示多行文字
下面我们用一个Demo来学习一下宽视图的主要用法及注意事项
效果图
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RadioGroup
android:id="@+id/options_group"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:te