1

I've added a sample picture into my app but it doesn't show on the device. What's wrong ?

enter image description here

user2925716
  • 949
  • 1
  • 6
  • 13
  • Sample data (`tools:srcCompat="@tools:sample/...`) is for development tools, such as Android Studio. – CommonsWare May 21 '22 at 20:21
  • @CommonsWare Sorry I didn't quite catch you. What is the right code to show up correctly on my device ? – user2925716 May 21 '22 at 20:28
  • 1
    Use `app:srcCompat` and point to an actual image, such as a drawable resource. Or, use an image-loading library (e.g., Glide, Picasso) and load an image at runtime (e.g., from a URL). – CommonsWare May 21 '22 at 20:38
  • @CommonsWare When typing `app:` the whispering doesn't offer anything. BTW, what is the difference between `app:` and `android:` headers ? – user2925716 May 21 '22 at 20:49
  • @CommonsWare Can I make the picture trasparent so that if it is over a `editarea` the letters are visible ? – user2925716 May 21 '22 at 21:04
  • @user2925716 you can make any UI transparent as long as it has an alpha attribute. You can use `imageView.setAlpha(0)` in java or ` – ganjaam May 22 '22 at 07:58
  • @user2925716 `app:` and `android:` are called namespaces. `android:` namespace is used for attributes of android SDK itself. refer to this link to learn more: https://stackoverflow.com/q/29732512/8192914 – ganjaam May 22 '22 at 08:07

1 Answers1

2

To display image, you should use app:srcCompat like the following.

<ImageView
            ...
            ...
            ...
            app:srcCompat="@drawable/resource_name" />

tools:srcCompat is responsible for showing the files in the IDE. It will not show the image in app.

Another approach to load image would be using Glide or Picasso library. You can find how to use them in their respective readme file.

ganjaam
  • 1,030
  • 3
  • 17
  • 29