Setting background image on a Activity Screen


Setting the background image of an activity screen on Android is very easy, just follow these steps:

  1. Copy your image that you wish to be the background to the \res\drawable directory folder
  2. Open the xml activity_main.xml layout file
  3. Add this to the RelativeLayout tag: android:background=”@drawable/image”

Sample code in XML

<RelativeLayout xmlns:android="<a class="linkification-ext" title="Linkification: <a class="linkification-ext" title="Linkification: http://schemas.android.com/apk/res/android" href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>" href="<a class="linkification-ext" title="Linkification: http://schemas.android.com/apk/res/android" href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"><a class="linkification-ext" title="Linkification: http://schemas.android.com/apk/res/android" href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a></a>"
    xmlns:tools="<a class="linkification-ext" title="Linkification: <a class="linkification-ext" title="Linkification: http://schemas.android.com/tools" href="http://schemas.android.com/tools">http://schemas.android.com/tools</a>" href="<a class="linkification-ext" title="Linkification: http://schemas.android.com/tools" href="http://schemas.android.com/tools">http://schemas.android.com/tools</a>"><a class="linkification-ext" title="Linkification: http://schemas.android.com/tools" href="http://schemas.android.com/tools">http://schemas.android.com/tools</a></a>"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/image"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"/>
</RelativeLayout>

Advertisements

3 thoughts on “Setting background image on a Activity Screen

  1. I just like the helpful information you provide on your articles. I will bookmark your blog and test once more here frequently. I’m moderately certain I will learn many new stuff right here! Best of luck for the next! gbdccegfcgcb

    Like

  2. I’m really enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Fantastic work!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s