不能';t扩展RemoteViews android

不能';t扩展RemoteViews android,android,exception,notifications,Android,Exception,Notifications,。我看到了类似的问题,但无法解决我的问题。 我使用带有自定义布局的通知。 在我的设备(sdk 16)上一切正常,但在android 2.3.7上,我的应用程序会抛出错误。 这是我的布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="

。我看到了类似的问题,但无法解决我的问题。 我使用带有自定义布局的通知。 在我的设备(sdk 16)上一切正常,但在android 2.3.7上,我的应用程序会抛出错误。 这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:orientation="horizontal">
    <ImageView
            android:id="@+id/notifAlbum"
            android:maxWidth="80dip"
            android:adjustViewBounds="false"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:scaleType="fitCenter"/>
    <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_gravity="center"
            android:orientation="vertical" android:paddingLeft="10dp">
        <TextView
                android:id="@+id/notifTitle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:ellipsize="marquee" android:textSize="18sp"
                android:textColor="@color/almost_white"/>
        <TextView
                android:id="@+id/notifArtist"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:ellipsize="marquee" android:textSize="14sp"/>
    </LinearLayout>
    <ImageButton
            android:id="@+id/notifPrevious"
            android:paddingTop="10dip"
            android:paddingBottom="10dip"
            android:layout_height="42dip"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:background="?android:attr/selectableItemBackground"
            android:scaleType="fitCenter"
            android:src="@drawable/widget_previous" android:baselineAlignBottom="false"/>
    <ImageButton
            android:id="@+id/notifPlay"
            android:paddingTop="6dip"
            android:paddingBottom="6dip"
            android:layout_height="42dip"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:background="?android:attr/selectableItemBackground"
            android:scaleType="fitCenter"
            android:src="@drawable/widget_play" android:paddingLeft="6dp" android:paddingRight="6dp"/>
    <ImageButton
            android:id="@+id/notifNext"
            android:paddingTop="10dip"
            android:paddingBottom="10dip"
            android:layout_height="42dip"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:background="?android:attr/selectableItemBackground"
            android:scaleType="fitCenter"
            android:src="@drawable/widget_next" android:longClickable="false"/>
    <ImageButton
            android:id="@+id/notifClose"
            android:layout_height="42dip"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:background="?android:attr/selectableItemBackground"
            android:scaleType="fitCenter"
            android:src="@drawable/close" android:paddingRight="4dp" android:paddingLeft="2dp"
            android:paddingTop="12dp" android:paddingBottom="12dp"/>
</LinearLayout>
下面是我如何构建通知

private RemoteViews getNotifViews(int layoutId)
    {
        RemoteViews views = new RemoteViews(getPackageName(), layoutId);

        Audio audio = audios.get(indexCurrentTrack);

        views.setTextViewText(R.id.notifTitle, audio.getTitle());
        views.setTextViewText(R.id.notifArtist, audio.getArtist());

        Bitmap cover = AlbumArtGetter.getBitmapById(audio.getAid(),this);
        if (cover == null)
        {
            views.setImageViewBitmap(R.id.notifAlbum, BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover));
        }
        else
        {
            views.setImageViewBitmap(R.id.notifAlbum, cover);
        }


        views.setImageViewResource(R.id.notifPlay, isPlaying ? R.drawable.widget_pause : R.drawable.widget_play);

        ComponentName componentName = new ComponentName(this,PlayingService.class);

        Intent intentPlay = new Intent(actionPlay);
        intentPlay.setComponent(componentName);
        views.setOnClickPendingIntent(R.id.notifPlay, PendingIntent.getService(this, 0, intentPlay, 0));

        Intent intentNext = new Intent(actionNext);
        intentNext.setComponent(componentName);
        views.setOnClickPendingIntent(R.id.notifNext, PendingIntent.getService(this, 0, intentNext, 0));

        Intent intentPrevious = new Intent(actionPrevious);
        intentPrevious.setComponent(componentName);
        views.setOnClickPendingIntent(R.id.notifPrevious, PendingIntent.getService(this, 0, intentPrevious, 0));

        Intent intentClose = new Intent(actionClose);
        intentClose.setComponent(componentName);
        views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(this, 0, intentClose, 0));

        return views;
    }

    private Notification createNotification()
    {

        Intent intentActivity;


        intentActivity = new Intent(FullPlaybackActivity.actionReturnFull);
        intentActivity.setClass(this,FullPlaybackActivity.class);
        intentActivity.putExtra(FileSystemActivity.keyMusic,audios);
        intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        Notification notification = new Notification();
        notification.contentView = getNotifViews(R.layout.notif);
        notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
        notification.contentIntent = PendingIntent.getActivity(this,0,intentActivity,PendingIntent.FLAG_UPDATE_CURRENT);
        notification.icon =  isPlaying ?  R.drawable.status_icon_pause : R.drawable.status_icon_play;

        return notification;
    }

我找到了异常的原因。这是因为我使用了带有
ImageButton
的自定义布局,这在旧设备上不支持(api级别<11)。可能对某人有帮助。

我也有同样的错误,但这是由于

android:background="?android:attr/selectableItemBackground"

删除此行解决了问题。

是remoteview不支持selectableitembackground。
android:background="?android:attr/selectableItemBackground"