DnwAlgorithma
DnwAlgorithma

Reputation: 119

Add background image to RelativeLayout in android

I tried to add a background image to an Android app using android:background="@drawable/imageURL". I added the image to the drawable-hdpi folder, but I'm getting an error. I'm trying to add the image to a RelativeLayout. I also tried to use LinearLayout but it didn't work either.

So how to add background image to my app within RelativeLayout in Android?

What is the error?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/abc.png"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" />

    </RelativeLayout>

Upvotes: 1

Views: 1386

Answers (2)

user3672487
user3672487

Reputation: 11

just write @drawable/abc instead of @drawable/abc.png

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157487

replace

android:background="@drawable/abc.png"

with

android:background="@drawable/abc"

From the documentation:

May be a reference to another resource, in the form "@[+][package:]type:name"

as you can see the extension is not part of the value of the attribute

Upvotes: 5

Related Questions