Adding Images to Drawable folder in Android Project


Hello there everyone,

This week we are going to see how to import images directly to the DRAWABLE folder in the Android Project

Step 1: Rename the image with only small cases and underscore (_) only

Step 2: The image can be in any format such as .jpg/.png

Step 3: Now, you can programmatically add them as given below

In XML:

app:srcCompat="@drawable/sample_image" // no need to mention extension

In JAVA:

testButton.setImageDrawable(getResources().getDrawable(R.drawable.sample_image));

NOTE:

THERE ARE SIMPLE WAY TO DO MANY THINGS IN ANDROID

WE JUST DON’T SEARCH / TRY HARDER