Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set Layout Background in Android UI

Tags:

java

android

I'm new to Android programming. I have a UI with some TextView and Button controls. How do I set a background behind those components? Lets call it background.png.

like image 313
farissyariati Avatar asked Nov 18 '11 04:11

farissyariati


Video Answer


2 Answers

in your parent layout element, e.g. linearlayout or whatever, simply add android:background="@drawable/background" This will set the background of your layout, assuming you have the image in a /drawable folder.

like image 191
LuxuryMode Avatar answered Sep 30 '22 11:09

LuxuryMode


First you have to place your background.png image in your res/drawable/ folder.Later you have to set a parent layout for your TextView and Button widgets.I will consider a LinearLayout as a parent layout for you and the code goes like this:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:background="@drawable/background.png" 
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
 <TextView    android:layout_width="fill_parent"
              android:layout_height="wrap_content" 
              android:text="@string/hello" />
 <Button      android:text="Button" 
              android:id="@+id/button1"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"></Button>
</LinearLayout>
like image 40
Vivek Kalkur Avatar answered Sep 30 '22 09:09

Vivek Kalkur