Friday, 12 July 2013

How to set background image in an android application

It's  simple to set background image for your android application. Below I have an example code for this as well.
  1. Create a new android application in Eclipse. (Here I have used 4.2 Jelly Bean version).
  2. Copy your image file to /res/drawable-mdpi directory.
  3. 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.









Tuesday, 4 June 2013

Android tutorial and examples

 

What is Android?

Android, an open source operating system for mobile devices (Smartphone and tablet), led by Google. The Android SDK provides a set of tools and APIs to develop Android applications, using Java. So, if you know Java, Android programming is easy :)

 

Note
All Android tutorials are developed in Eclipse Juno 4.2, and tested with Android Jelly Bean 4.2.2.

 

Android installation steps:-

Android programming  starts with downloading of android sdk called adt bundle for windows this is available at this link http://developer.android.com/sdk/index.html  download this zip file contains  With 32-bit and 64-bit versions

  • Extract  the zip file. Its consists of latest version of eclipse IDE and  android SDK
  •  Open eclipse IDE
  • Choose the window option 
  • In window select preferences  in this set android sdk location 

 

Few Steps to add Android SDK :-  

  •  In Eclipse: select Window > Preferences.

 

  • In left side panel click on Android option. In right side panel click on Browse button and add SDK location, then click on Apply and Ok butons

 

 

Few steps to create Emulator:-

Creating an AVD
You can create as many AVDs as you would like to test on. It is recommended that you test your applications on all API levels higher than the target API level for your application.

  To create an AVD:

  • In Eclipse: select Window > AVD Manager, or click the AVD Manager icon in the Eclipse toolbar.

 

 

  • In Android Virtual Device Manager click on New.. button.

 

 

  • In nex step fill the details in Create new Android Virtual Device (AVD) then click on ok button.
  • In next step select your device and click on start button

 

  •   In next step you get Launch Options window then click on Launch button

 

  • And finally you get Emulator what ever you created.

 

  •   So finally using this Emulator you can run your Android applications.