我正在编写一些 Android 代码来处理 GCM 通知。我在大多数应用程序中看到,当通知到来时,它会以简短文本的形式显示在主屏幕上,但是当我们按住它并向下拉时,它也会显示消息的其余部分。我想在我的代码中实现它。我的代码是这样的:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setLargeIcon(bm)
.setSmallIcon(R.drawable.some_pic)
.setContentTitle("Some Title")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
但是还是不行。我还需要添加什么,以便它不仅显示末尾带有“...”的单行文本,而且在下拉通知时显示整个消息?
最佳答案
我认为通知的可扩展 View 将帮助您以可扩展模式显示整个消息。 你可以使用这样的扩展 View 吗?
RemoteViews expandedView=new RemoteViews(context.getPackageName(),
R.layout.notification_expendable_view);
expandedView.setTextViewText(R.id.notification_expendable_text,
your entire message);
Notification notification = notificationBuilder.bulid();
notification.bigContentView = expandedView;
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(101, notification);
以及布局文件夹名称中带有 notification_expendable_view 的布局文件。
notification_expendable_view.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/notification_expendable_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinerLayout>
关于android - 如何在 Android 的 GCM 通知中实现 "tap-hold and pull down to show the entire message",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34149571/