0
<?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="96dp"
    android:gravity="center"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical"
        android:paddingStart="24dp"
        android:paddingBottom="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/pushIcon"
                android:layout_width="16dp"
                android:layout_height="16dp"
                app:srcCompat="@drawable/push_icon" />

            <TextView
                android:id="@+id/textView23"
                style="@style/TextAppearance.Compat.Notification.Info.Media"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="6dp"
                android:text="YOLOL"
                android:textColor="@color/browser_actions_title_color" />
        </LinearLayout>

        <TextView
            android:id="@+id/text_view_collapsed_1"
            style="@style/TextAppearance.Compat.Notification.Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:text="New Message!"
            android:textColor="@color/colorPrimary" />

        <TextView
            android:id="@+id/text_view_collapsed_2"
            style="@style/TextAppearance.Compat.Notification.Info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Expand to show!" />
    </LinearLayout>

    <ImageView
        android:id="@+id/notifPreviewImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        app:srcCompat="@drawable/bb" />

</LinearLayout>

The pushIcon ImageView takes the place but is invisible, any idea why?

E_net4
  • 27,810
  • 13
  • 101
  • 139
  • @Edward, instead of using app:srcCompat, try using android:src . Also is it invisible from the view higherarchy do you mean YOU don't see it? Confirmation from the view hierarchy would be more definitive. – JoxTraex Dec 31 '20 at 22:36
  • 1
    @JoxTraex yey it works, thanks! When you post this as answer I will check –  Dec 31 '20 at 22:39

1 Answers1

5

A quick tip that always helps in the debug process - add a background color to the view in question (also helps to set a specific Width and Height as well for testing) - it will enable you to see if the view is being rendered at all or not. If you see the background color, then the view is being rendered properly, but the image is not loading correctly. Without knowing this, it could be any combination of those issues.

With that aside, if you are dynamically changing the icon at runtime, I would look at your code there. If this is a static image then I would check that your resource file is a Vector drawable as that is only allowed when using app:srcCompat="@drawable/push_icon"

If your file is a non-vector drawable, then use android:src="@drawable/push_icon"

Here's a discussion that elaborates on this in more detail.

zuko
  • 707
  • 5
  • 12
  • in addition to the tip, you could also just look at the view hierarchy as well, that way you don't have to modify the layout :) but knowing about both is very important. The reason is because it might be the view has 0 height but is visible, so you'd need to check the hierarchy for that. – JoxTraex Jan 20 '21 at 02:28
  • Changing to "android:src" worked for me. Thanks – codeCooker Jul 23 '22 at 22:01