【发布时间】:2016-09-03 17:52:48
【问题描述】:
请帮我在自定义通知中设置文本视图中的文本
private void startNotification()
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
RemoteViews notificationView = new RemoteViews(getPackageName(),R.layout.mynotification);
mRemoteViews.setTextViewText(R.id.appName, getResources().getText(0,"gfhf"));
mBuilder.setContent(mRemoteViews);
Intent notificationIntent = new Intent(this, FlashLight.class);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentView = notificationView;
notification.contentIntent = pendingNotificationIntent;
notification.flags |= Notification.FLAG_NO_CLEAR;
Intent switchIntent = new Intent(this, switchButtonListener.class);
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, 0);
notificationView.setOnClickPendingIntent(R.id.closeOnFlash, pendingSwitchIntent);
notificationManager.notify(1, notification);
}
java.lang.NullPointerException: 尝试调用虚方法 'void android.widget.RemoteViews.setTextViewText(int, java.lang.CharSequence)' 在空对象引用上
请帮我解决这个问题。如何在android的通知中设置textview的值,提前谢谢。
【问题讨论】:
-
你到底想要什么??您想使用自定义样式 textView 创建自定义通知吗?为此创建自定义类并覆盖 DefaultNotificationFactory 并创建您自己的视图
标签: android sdk android-notifications