我有一个xml文件定义如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="notif"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
我正在尝试将此xml文件添加到通知中,这是我到目前为止所做的:
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.custom_layout);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.ic_launcher).setContent(
remoteViews);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, Receiver.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
但是当我尝试像这样添加它时,我收到错误“从包[包名称]发布错误通知。无法展开RemoteViews”
有人可以告诉我这里做错了什么。谢谢!
答案 0 :(得分:0)
RemoteView
的布局不支持EditText
。尝试用TextView
替换它
您可以参考this list查看RemoteView
希望有所帮助