如何在使用通知样式或需要自定义布局的android中首次显示通知中的全部内容?如何在android中创建自定义通知布局?
11
A
回答
2
我用BitTextStyle()在通知中添加突出显示的文本。
return new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_mono)
.setContentTitle(title)
.setContentText(message)
.setLargeIcon(icon)
.setColor(ContextCompat.getColor(context, R.color.notification_color))
.setStyle(new NotificationCompat.BigTextStyle().bigText(title))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message).setSummaryText("#hashtag"))
.setShowWhen(true)
.setAutoCancel(true);
45
使用您的通知生成器
定义自定义通知布局定制
contentView
,通过实例化一个 RemoteViews对象膨胀的XML布局文件启动。然后,而不是 调用方法,如setContentTitle(),调用setContent()
。若要设置自定义通知 内容的详细信息,使用方法RemoteViews
设置视图的孩子的价值观:在一个单独的文件创建的通知的XML布局。您可以使用任何您想要的文件名,但必须使用扩展名.xml 在您的应用中,使用
RemoteViews
方法来定义通知的图标和文本。通过调用setContent()将此对象放入您的NotificationCompat.Builder
中。避免你的RemoteViews对象上设置一个 背景绘制对象,因为你的文字 颜色可能变得不可读。
custom_push.xml有我的自定义视图R.id.image,R.id.text,R.id.title
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:padding="10dp" >
<ImageView
android:src="@mipmap/ic_launcher"
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView
android:textSize="13dp"
android:textColor="#000"
android:text="Testing"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
/>
<TextView
android:textSize="13dp"
android:textColor="#000"
android:text="Testing is awecome"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:layout_below="@id/title"
/>
</RelativeLayout>
实例化一个RemoteViews对象,并设置它,
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_push);
contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
contentView.setTextViewText(R.id.title, "Custom notification");
contentView.setTextViewText(R.id.text, "This is a custom layout");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContent(contentView);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(1, notification);
检查:https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ApplyStyle
3
我想你要找的是什么.setSubText()
。 您指出的flipkart通知绝对不是自定义视图。
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(icon)
.setSubText("Limited Stocks, Don't Wait!") <-------
.setContentTitle("Custom Notification Title")
notificationBuilder.notify(1, notificationBuilder.build());
相关问题
- 1. 在android中创建自定义布局
- 2. 在Android中创建自定义布局
- 3. 在android中创建自定义通知
- 4. 自定义通知布局
- 5. 如何在android中的布局中创建自定义菜单?
- 6. 如何在android中创建自定义布局?
- 7. 如何在android中为seekbar创建自定义布局?
- 8. 创建自定义Android键盘布局
- 9. android创建自定义形状布局
- 10. 如何创建自定义布局?
- 11. X10中的自定义通知布局
- 12. 在BlackBerry中创建自定义布局
- 13. 如何在android中创建自定义通知
- 14. 如何创建自定义声音通知在Android的
- 15. 如何使用自定义布局创建android快餐栏
- 16. 自定义通知布局崩溃在Android 6.0和4.3上
- 17. 如何在SugarCRM中为自定义视图创建布局
- 18. 如何在崇高文字2中创建自定义布局?
- 19. 如何在websphere portal 8中创建自定义布局
- 20. 如何在Grails中创建自定义视图和布局
- 21. 如何在iOS中创建自定义通知中心swift
- 22. 如何在Android中定义自定义(复合)布局?
- 23. AndroidTV - 创建自定义布局
- 24. 创建自定义布局ExtJs 4.1
- 25. 创建自定义布局(背景)
- 26. 创建自定义布局模块
- 27. 创建自定义d3布局
- 28. 创建自定义JSON布局PHP
- 29. 在Android中创建自定义通知栏
- 30. android搜索:自定义建议布局
所以,我需要自定义视图。对? –
@khaleel_jageer在给定的链接中有一个称为**自定义通知布局**的阅读,如果你没有得到它 –
这应该是公认的答案! – Kaushal28