Pr.Pg Next Pg

Backgrounds and Resources tutorials

 

Adding Resources to the Project

  • If you want to add resources such as .mp3 files or images for your android project, you can do it by placing them in the res folder.

  • Generally the images are in the drawable folder and for music files you can create a new folder.

  • In our example we will create a new folder music which contains an .mp3 file and add an image named background.png to the drawable-hdpi (we can also add images for mdpi and ldpi).

  • We can open the file Explorer of the computer and can the resources as mentioned above.

  • Make sure that the image saved has the name in all Lowercase letters.

  • After adding them into the folders, refresh in eclipse and you can see the image in the drawable folder under res

  • folder.

  • Now we have to create a new layout that will add this image as its background.

 

To create a new layout

  • Right click on the layout folder in the package explorer.

  • Click on New > Other > Android XML Layout File .

  • Mention the name of the Layout file (in our example I have used test).

  • After clicking the Finish button a new layout will be added to the layout folder.

 

 

  • Now open the test.xml file and add the attribute android:background=”@drawable/background”

  • Do not add the extension in the filename (png,jpeg,etc).

  • You can then see the Layout in the graphical section by clicking on the tab below.

 

  • Backgrounds and Resources

 

 

Pr.Pg border                                              Next Pg