Android 不能';t展开远程视图
我正在使用远程视图为媒体播放器生成自定义通知。但是当我调用showNotification()方法时,得到了以下异常 生成自定义通知的Java代码Android 不能';t展开远程视图,android,android-notifications,remoteview,android-remoteview,Android,Android Notifications,Remoteview,Android Remoteview,我正在使用远程视图为媒体播放器生成自定义通知。但是当我调用showNotification()方法时,得到了以下异常 生成自定义通知的Java代码 public void showNotification() { if (mRemoteViews == null) { mRemoteViews = new RemoteViews(getPackageName(), R.layout.player_notification); } Notificatio
public void showNotification() {
if (mRemoteViews == null) {
mRemoteViews = new RemoteViews(getPackageName(), R.layout.player_notification);
}
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification = new NotificationCompat.Builder(MPService.this)
.setSmallIcon(R.drawable.status_icon)
.setOngoing(true)
.setContent(mRemoteViews);
mRemoteViews.setTextViewText(R.id.player_notification_title, AppConstant.playerTitle);
notificationManager.notify(0, mNotification.build());
}
XML代码(player_notification.XML)
我也读过关于这个异常的堆栈溢出的文章,但是没有找到解决这个问题的方法
我认为远程视图有一些问题。但我没办法弄明白
public void showNotification() {
if (mRemoteViews == null) {
mRemoteViews = new RemoteViews(getPackageName(), R.layout.player_notification);
}
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification = new NotificationCompat.Builder(MPService.this)
.setSmallIcon(R.drawable.status_icon)
.setOngoing(true)
.setContent(mRemoteViews);
mRemoteViews.setTextViewText(R.id.player_notification_title, AppConstant.playerTitle);
notificationManager.notify(0, mNotification.build());
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/switch_thumb_normal_material_light"
android:orientation="vertical">
<ImageView
android:id="@+id/player_image"
android:layout_width="41dp"
android:layout_height="41dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="16dp"
android:src="@drawable/ic_launcher_sample" />
<TextView
android:id="@+id/player_notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="70dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/closebutton"
android:layout_toRightOf="@id/player_image"
android:singleLine="true"
android:textColor="@color/colorPrimary"
android:textSize="18sp"
/>
<TextView
android:id="@+id/textViewApp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/player_notification_title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_toRightOf="@id/player_image"
android:singleLine="true"
android:text="Sample"
android:textColor="@color/colorPrimary"
/>
<ImageButton
android:id="@+id/closebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/list_image_margin"
android:background="@drawable/ic_clear_black_24dp" />
<ImageView
android:id="@+id/bar_btn_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="25dp"
android:layout_toLeftOf="@id/closebutton"
android:background="@drawable/ic_play_notification"
android:backgroundTint="@color/colorPrimary"
android:visibility="gone" />
<ImageView
android:id="@+id/bar_btn_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="25dp"
android:layout_toLeftOf="@id/closebutton"
android:background="@drawable/ic_pause_notification"
android:backgroundTint="@color/colorPrimary" />
</RelativeLayout>