Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Background Image in XML File

I currently have an application which has the default black background for every slide. What I would like to do is alter the XML files to have a background image. I'm assuming there is a simple command for this but haven't been able to find exactly what I'm looking for.

I want an image to the background of my current screen. I don't want the background to ever change, and I would like to put this in my XML file. Here is an example of one of my XML headers...

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
   android:weightSum="9"
   android:gravity="center"
    >

...

I am assuming there is some simple command such as

android:background="file"
like image 510
JuiCe Avatar asked Nov 26 '12 13:11

JuiCe


People also ask

How to add image in XML file in android Studio?

xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView. Select the image you want press Ok you can see the image on the Design view.

How to set image in Drawable XML android?

To use an image resource, add your file to the res/drawable/ directory of your project. Once in your project, you can reference the image resource from your code or your XML layout. Either way, it's referred to using a resource ID, which is the file name without the file type extension. For example, refer to my_image.


2 Answers

Just use android:background="@drawable/file_name_without_extension"

If your file is on SD card you can't put it on xml layout.

like image 102
jaumard Avatar answered Oct 29 '22 17:10

jaumard


android:background = "@drawable/imagename"

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background = "@drawable/imagename"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
   android:weightSum="9"
   android:gravity="center"
    >

...
like image 26
Kanaiya Katarmal Avatar answered Oct 29 '22 16:10

Kanaiya Katarmal