Create a custom "Big Notifications"
来源:互联网 发布:宏观经济基础数据库 编辑:程序博客网 时间:2024/06/07 05:46
实现自定义布局的Notification,该文源自:http://stackoverflow.com/questions/21237495/create-custom-big-notifications
So after excessive google usage, I found this tutorial explaining how to use custom big layouts. The trick is not to use setStyle()
but manually set the bigContentView
field of the Notification
after building it. Seems a bit hacky, but this is what I finally came up with:
notification_layout_big.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="100dp" <!-- This is where I manually define the height --> android:orientation="horizontal" > <!-- some more elements.. --> </LinearLayout>
Building Notification
in code:
Notification foregroundNote;RemoteViews bigView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_layout_big);// bigView.setOnClickPendingIntent() etc..Notification.Builder mNotifyBuilder = new Notification.Builder(this);foregroundNote = mNotifyBuilder.setContentTitle("some string") .setContentText("Slide down on note to expand") .setSmallIcon(R.drawable.ic_stat_notify_white) .setLargeIcon(bigIcon) .build();foregroundNote.bigContentView = bigView;// now show notification..NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);mNotifyManager.notify(1, foregroundNote);
0 0
- Create a custom "Big Notifications"
- Create a Custom Master Page
- Create a Custom Listfield - Change Highlight Color
- How to: Create a Custom List Definition
- Create A Custom Theme in Magento
- create a custom shipping method in magento
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- iOS开发20-iOS开发中要注意的循环引用
- iOS——计算项目代码行数
- 曲线平滑方法
- LeetCode Power of Two 位运算
- git pull出现There is no tracking information for the current branch
- Create a custom "Big Notifications"
- 安卓5.1 TextView屏蔽长按复制粘贴
- 解决Xcode 7 无法推送 或者 打印错误 "remote-notification"
- 程序员常去的14个顶级开发社区
- 正则表达式30分钟入门教程
- setsockopt详解
- 属性 iOS笔记
- 数组与指针详解
- 鲁大师检测硬盘提示有问题,如下图,是怎么回事?硬盘坏了吗