How to show image on an android application

ImageView Widget in Android

What you should already KNOW?

You should be familiar with:

1) Creating, building, and running apps in Android Studio

2) Basics of android widgets


Explanation: Image View widget is used to insert the image into an activity. There are several attributes of the Image View widget. With the help of android:srcCompat attribute we can set the source of the image we want to insert into an activity.


Xml File:

In the srcCompat Attribute, physical address of the image is passed.

Java file:

Image view does not require an java file to be touched (Strictly while working with android studio). But to change the source of the image at the run time of the application, java file is used.

Step by step explanation of the java code:

1) Create an instance variable of ImageView class inside the mainActivity class.

2) Assign the ImageView object to the imageView instance like this inside the onCreate() method.

3) Use method setImageResource of ImageView class to change :

Output Screen: