自定义通知视图不显示图像



我正在尝试在通知栏上显示一个图标和一个文本。所以我为此创建了一个新的布局,但只有文本显示,图标没有。

这就是我创建通知的方式:

val notification = NotificationCompat.Builder(this, notificationChannelId)
.setOngoing(true)
.setContentTitle(getString(R.string.app_name))
.setCustomBigContentView(RemoteViews(packageName, R.layout.notification_view))
.setSmallIcon(R.drawable.ic_launcher)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
.build()

这是我的通知布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent">
<ImageView
android:id="@+id/ic_someid"
android:layout_width="15dp"
android:layout_height="15dp"
app:srcCompat="@drawable/ic_someicon" />
<TextView
android:id="@+id/text_sometext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test..." />
</LinearLayout>

我的问题是为什么图标没有显示在通知栏中?

app:srcCompat="@drawable/ic_someicon"替换为android:src="@drawable/ic_someicon"。您不能在任何RemoteViews场景(自定义通知、应用程序小部件等(中使用前缀为app的属性

最新更新