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
.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With