Reputation: 1157
I'm a bit of a Android noob, as of today.
I have tried setting a picture to the background as follows;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="C:\Users\Jacob\Downloads\xmas.jpg"
android:layout_height="match_parent"
tools:context=".MainActivity" >
But when i build it comes up with;
'Description Resource Path Location Type error: Error: String types not allowed (at 'background' with value 'C:\Users\Jacob\Downloads\xmas.jpg'). activity_main.xml /FirstAndroidApp/res/layout line 1 Android AAPT Problem'
When i go in to the designer it shows the background as i would like it, but just comes up with an error.
Am I not allowed to set a background in this way? or am i missing something?
Upvotes: 0
Views: 1311
Reputation: 18489
In android you should not set background like this. Search a little and you can get your answer.
android:background="C:\Users\Jacob\Downloads\xmas.jpg"
to android:background="@drawable/xmas"
In android .png is more recommended to use and while using like as i said above no need to give extension like .png or .jpg..
This will solve your problem
Upvotes: 1
Reputation: 132972
to get work it you will need to copy your image in <Your_Project>/res/drawable
folder and then set RelativeLayout
background as :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/xmas"
android:layout_height="match_parent"
tools:context=".MainActivity" >
and for more information for adding images in your project see
http://developer.android.com/guide/topics/resources/drawable-resource.html
Upvotes: 1
Reputation: 36449
You have to copy the picture into your drawable
folder then reference it like so:
android:background="@drawable/xmas"
Upvotes: 1