Home > Back-end >  Custom Notification View Doesn't Show Images
Custom Notification View Doesn't Show Images

Time:10-16

I'm trying show an icon and a text on my notification bar. So I created a new layout for that, however only the text shows up and the icon doesn't.

This is how I create the notification:

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()

And this is my notification layout:

<?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>

My question is why does the icon doesn't show up in the notification bar?

CodePudding user response:

Replace app:srcCompat="@drawable/ic_someicon" with android:src="@drawable/ic_someicon". You cannot use app-prefixed attributes with any RemoteViews scenario (custom notifications, app widgets, etc.).

  • Related