It's simple to set background image for your android application. Below I have an example code for this as well.
- Create a new android application in Eclipse. (Here I have used 4.2 Jelly Bean version).
- Copy your image file to /res/drawable-mdpi directory.
- Open your layout xml file activity_main.xml and add below line;
BackgroundImage program structure...
activity_main.xml file
android:background="@drawable/android"
Here 'android' is the name of the image without extension
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/android"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Run your application. The image will be applied as background for this layout.
Thanks for posting.
ReplyDelete