Search Wikipedia

Search results

Oct 13, 2013

Using resources and setting background

Setting some resources in my projects


Today i am gonna learn  to add resources in my project and use such resources.
First of all i make a new android project named Backapp.


One of the way of adding resources is by going to eclipse Worskspace folder and inside my project there is res folder where i can add my resources.Here i will add a background image in drawable-hdpi folder.I can add image in 4 different resolutions but in this project i am  being  lazy so i am just using one resolution.

Adding resources in my project
Or we can directly add resources like image in my project by dragging or copying the image in drawable folder in eclipse.

Here i have a background image in drawable folder but it has not been updated in eclipse. In this condition, i have to clean my project. For this goto main panel there is Project->Clean

Cleaning the project to make update

And a new window appears and click clean and the problem is solved.


Here i am using 400*600 resolution image.

In addition of image i also want to add  a sound in my project. For this i will make a raw folder in res folder.
Right clicking the res folder. 
New->Folder
 A new window will appears and i name my folder name "raw" and click finish.
Sound can be added in this folder following same step like in adding image in drawable folder.

Adding more resources like sound in my project

Now to put background in my layout, go to activity_xml and 
 write this short code:

android:background="@drawable/background"


Putting background in layout

Now i run this project in my AVD and it appears like this.

Running my project in AVD

No comments:

Post a Comment

Did this post help you? Do you have any questions? Drop your thoughts here...

}