0

I have a background

enter image description here

is not a simple color I do not know how to set the background of your application

Max Usanin
  • 2,479
  • 6
  • 40
  • 70

3 Answers3

2

So if you want to display image in background and repeat it put this code in drawable folder: bg.xml

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/your_image"
    android:tileMode="repeat" />

and then simply apply this to your root view: android:background="@drawable/bg"

Sabre
  • 4,131
  • 5
  • 36
  • 57
1

(1) Put your background image (e.g. my_image_name.png) in res/drawable folder. Hint: you can have different resolution images for different device densities (hdpi, mdpi) -- just place same name PNGs in the appropriate res/drawable-xxx folders.

(2) To get the tiled look-and-feel, create a res/drawable/my_back.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

  <item>
    <bitmap
      android:src="@drawable/my_image_name"
      android:tileMode="repeat" />
  </item>

</layer-list>

(3) Next, create a new layout, e.g. res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/my_back" >

<!-- add your elements here -->

</FrameLayout>

(4) Finally, use the newly created layout with the tiled background in your Activity:

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }

That's it.

Saran
  • 3,845
  • 3
  • 37
  • 59
0

Use the android:background property.

You can define a Drawable Resource using that image, and specify how you want it to tile and so forth in the XML for the drawable.

jbowes
  • 4,062
  • 22
  • 38