0

我正在尝试在 Android 2.3.3 上构建通知。我需要自定义布局,但无法使用 Notification Builder。这是通知的布局:

R.layout.notification_upload

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative_notification_upload"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageview_icon"
        android:layout_height="match_parent"
        android:layout_marginRight="10dp"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher"
        android:contentDescription="@string/icon" >
    </ImageView>

    <ProgressBar
        android:id="@+id/progress_bar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:indeterminate="true" >
    </ProgressBar>

</RelativeLayout>

这是通知的代码:

NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);

Intent intent = new Intent(context, HomeActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
        intent, 0);
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_upload);

Notification notification = new Notification();

notification.when = 0;
notification.icon = R.drawable.ic_launcher;
notification.contentIntent = pendingIntent;
notification.contentView = contentView;

notificationManager.notify(0, notification);

我收到:从包裹中发布的错误通知:无法扩展 RemoteViews 以用于... 我哪里出错了?我可以在通知中使用 ImageView 吗?

4

0 回答 0