31 Dec 2012


How to create your own Theme in Android

Theme in Android means applying the same style to a single activity or whole application .
Note:
  • If you will apply theme to a single activity then the style will appear to that particular activity .
  • If you will apply theme to whole application then the style will appear to the whole application.
Theme 1
Now if you like a theme and want to alter it of tweak it then follow this blog.
  • Now start with a project by selecting new-> file-> Android Application Project.
  • Fill the following details in the project.
  • Theme 2
    • Application Name- AndroidTheme
    • Project Name -AndroidTheme
    • Package Name- theme.android
    • Minimum required SDK - 2.2 froyo  and then click next and next then finish.

29 Dec 2012


How to change the Theme in Android App

Theme in Android means applying the same style to a single activity or whole application .
Note:
  • If you will apply theme to a single activity then the style will appear to that particular activity .
  • If you will apply theme to whole application then the style will appear to the whole application.
Theme 1
Now lets us learn how to change the theme in android.
  • Now start with a project by selecting new-> file-> Android Application Project.
  • Fill the following details in the project.
  • Theme 2
    • Application Name- AndroidTheme
    • Project Name -AndroidTheme
    • Package Name- theme.android
    • Minimum required SDK - 2.2 froyo  and then click next and next then finish.

28 Dec 2012


Various Themes available in Android

A Theme in Android is a style which is applied to whole application or a single activity.Android has provided a large collection of themes defined under R.style class.
So the various Themes which are available according to the version are given below.


Theme

In API level 10 or lower
  • <style name="Theme">  -This is the default themes for app in API level 10 or lower.other variant for this themes are:
    • <style name="Theme.NoTitleBar">
    • <style name="Theme.NoTitleBar.Fullscreen">
  • <style name="Theme.Light"> -It has a light background with dark text on the top.other variant for this themes are:
    • <style name="Theme.Light.NoTitleBar">
    • <style name="Theme.Light.NoTitleBar.Fullscreen">
  • <style name="Theme.Black"> -Its background is completely black ,useful for image viewer and media player .Other variant for this themes are:
    • <style name="Theme.Black.NoTitleBar">
    • <style name="Theme.Black.NoTitleBar.Fullscreen">
  • <style name="Theme.Wallpaper"> -It puts user selected themes as a background.Other variant for this themes are:
    • <style name="Theme.Wallpaper.NoTitleBar">
    • <style name="Theme.Wallpaper.NoTitleBar.Fullscreen">
  • <style name="Theme.WallpaperSettings"> - It is for wallpaper setting activity ,designed to be a transparent background with a dark shade so that previous activity remains visible in the background.
  • <style name="Theme.Light.WallpaperSettings"> - It is for wallpaper setting activity ,designed to be a transparent background with a light shade so that previous activity remains visible in the background.
  • <style name="ActiveWallpaperSettings"> -Style to apply on the top of wallpaper setting themes when it is being shown on the top of real walpaper.
  • <style name="PreviousWallpaperSettings"> -Style to apply on the top of wallpaper setting themes when it is being shown on the top of real walpaper.
  • <style name="Theme.Translucent"> -It allows you to see through them the window behind.Other variant are:
    • <style name="Theme.Translucent.NoTitleBar">
    • <style name="Theme.Translucent.NoTitleBar.Fullscreen">

27 Dec 2012


How To Create List View In Android

List view is a ViewGroup single dimensional and scrollable view to the user.List View has some important points:
  • ListView is automatically inserted in the layout using ListAdapter(a bridge between ListView and data which backs the list).
  • android.widget.ListView is the class which needs to import for implementing the list view.
List view 1
so lets us learn how to user list view:
  • First start the eclipse and select new-> android application project.
List view 2
  • Now fill the following details in the android application project interface.
    • Application Name- ListView
    • Project Name-ListView
    • Package Name-list.view
    • and then click next ->next and then finish.
List view  3

25 Dec 2012


How To Create Grid View In Android

GridView is a ViewGroup which provides two-dimensional and scrollable view to the user.Grid view has some important points:
  • GridView is automatically inserted in the layout using  ListAdapter(a bridge between ListView and data which backs the list).
  • android.widget.GridView is the class which needs to import for implementing the grid view.

so lets us learn how to create grid view.
  • first start the eclipse and select new-> android application project.
Grid View 1

  • Now fill the following details in the android application project interface.
    • Application Name- GridView
    • Project Name-GridView
    • Package Name-grid.view
    • and then click next ->next and then finish.

Grid View 2
  • Now in the project GridView open the activity_main.xml file under res-> layout-> activity_main.xml and replace the whole lines with these new lines.
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
     android:layout_width="fill_parent"  
     android:layout_height="fill_parent">  
     <GridView  
       android:id="@+id/gridView1"  
       android:layout_width="match_parent"  
       android:layout_height="match_parent"  
       android:background="#aabbcc"  
       android:numColumns="2"  
       android:verticalSpacing="5dp" >  
     </GridView>  
   </LinearLayout>  

24 Dec 2012


How To Create Options Menus in Android Application

In Android application, menus are the common user interface components which gives user a dynamic user experience. The other details about menus are:
  • android.view.Menu is class which provides the functionality of menu.
  • Till the Android version 2.3 , dedicated menu hardware button is provided for the menu option.
  • After Android version 3.0 and higher, no dedicated button is provided but instead another ways are provided according to type of menu to access the menu.
  • There are three types of Menus or action used in all version of menus.
    1. Option menu and action bar-It is presented by action bar as a combination of on-screen action bar and overflow options.
    2. Context menu and contextual action mode-It is presented by contextual action mode for enabling the menu and selected item.
    3. Pop up menu
so now lets learn how to add Option menus in our android application.
  • First start your eclipse and select new -> project and click next.
  • Now fill with following details:
    • Project name- OptionMenu
    • Application name-OptionMenu
    • package name-option.menu
    • Minimum required SDK- select android 3.0
    • tick on create custom laucher icon.
    • Name the activity -Optionmenu
    • tick on create project in workspace.
Option menu 1
  • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
  • Now for creating menu we will use xml format to define menu item.so open.so for creating the xml file open the project OptionMenu-> res-> menu and right click on menu sub-folder and select the new file name it as mainmenu.xml.

Option menu 2
  • Now open the mainmenu.xml file and add the following xml lines in the file.
1:    <menu xmlns:android="http://schemas.android.com/apk/res/android">  
2:      <item android:id="@+id/facebook"   
3:        android:title="@string/facebook"   
4:        android:icon="@drawable/facebook">  
5:      </item>  
6:      <item android:id="@+id/wordpress"   
7:        android:title="@string/wordpress"   
8:        android:icon="@drawable/wordpress">  
9:      </item>  
10:      <item android:id="@+id/google"  
11:         android:title="@string/google"  
12:         android:icon="@drawable/google" android:showAsAction="ifRoom">  
13:      </item>  
14:    </menu>  

  • Now let's understand the details of above mainmenu.xml lines.
    • At line 1,we have added first menu item in which we have given title and icon for the menu.
    • Title is defined in the string.xml file.
    • Icon image is given in the drawable folder.
    • Similarly we have added three menu item in th emainmenu.xml file.
    • At line 12 ,android:showAsAction="ifRoom"  is added which means it will appear in the action bar to provide quick access.
  • Now open the strings.xml file by clicking res-> values-> strings.xml and the few lines to it so that it finally look like this.In the file given below we have added the three Title string for the menu like Facebook, Google., WordPress. 
1:  <resources>  
2:    <string name="app_name">OptionMenu</string>  
3:    <string name="hello_world">Hello world!</string>  
4:    <string name="menu_settings">Settings</string>  
5:    <string name="title_activity_main">MainActivity</string>  
6:    <string name="facebook">facebook</string>  
7:    <string name="wordpress">wordpress</string>  
8:    <string name="google">google</string>  
9:  </resources>  

23 Dec 2012


How To Replace Default Background Of Multistate ImageButton In Layout


Multistates buttons are useful for showing the various states of buttons like pressed,focussed,normal state. For creating multistate button in the layout we need to use two classes .
  • First one, android.graphics.drawable.StateListDrawable class,which creates a drawable objects to show different images on same graphics based on the state of objects.Here each graphics is represented by <item> elements inside single <selector> elements.
  • Second one, android.widget.ImageButton class.It display an button with image in background and can be pressed.IT changes color during different state of button like focused, pressed etc.
So lets begin the programming step by step:
  • first open the eclipse select File -> New -> Project.
Default Multistate 1
  • Then Select Android -> Android Application Project and then click next.
  • Now fill with following details:
    • Project name- MultistateButton
    • Application name-MultistateButton
    • package name-multistate.Button
    • Minimum required SDK- select android 3.0
    • tick on create custom laucher icon.
    • tick on create project in workspace.
Default Multistate 2
  • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
  • Now we will create Multistate button file name as multistate_button.xml .but before doing this let us know the different state of button.
    • drawable- must for showing the normal state image.must refer to the image.
    • state_pressed-when object is pressed(touched/clicked) ,by default remains  non-pressed .
    • state_focused-when object has input focussed(when user selects text input).
    • state_hovered-when object is hovered by cursor , very similar to focused state.
    • state_selected-when object are selected through directional control inside focused state.
    • state_checkable-when object is checkable.object should be a type of check or unchecked.
    • state_checked-when object is checked.
    • state_enabled-when objects are enabled(are able to receive clicks or touch)
    • state_window_focused-when application window has focus means app comes in foreground.
  • Now in multistate_button.xml file we will use pressed, focused. so lets begin.
    • select MultistateButton project.
    • right click on drawable folder and click on new.
    • and write multistate_button.xml and then finish.

17 Dec 2012


Add a Text With Multistate Imagebutton In Layout



Multistates buttons are useful for showing the various states of buttons like pressed,focussed,normal state. For creating multistate button in the layout we need to use two classes .
  • First one, android.graphics.drawable.StateListDrawable class,which creates a drawable objects to show different images on same graphics based on the state of objects.Here each graphics is represented by <item> elements inside single <selector> elements.
  • Second one, android.widget.ImageButton class.It display an button with image in background and can be pressed.IT changes color during different state of button like focused, pressed etc.
So lets begin the programming step by step:
  • first open the eclipse select File -> New -> Project.
  • Then Select Android -> Android Application Project and then click next.
  • Now fill with following details:
    • Project name- MultistateButton
    • Application name-MultistateButton
    • package name-multistate.Button
    • Minimum required SDK- select android 3.0
    • tick on create custom laucher icon.
    • tick on create project in workspace.
  • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
  • Now we will create Multistate button file name as multistate_button.xml .but before doing this let us know the different state of button.
    • drawable- must for showing the normal state image.must refer to the image.
    • state_pressed-when object is pressed(touched/clicked) ,by default remains  non-pressed .
    • state_focused-when object has input focussed(when user selects text input).
    • state_hovered-when object is hovered by cursor , very similar to focused state.
    • state_selected-when object are selected through directional control inside focused state.
    • state_checkable-when object is checkable.object should be a type of check or unchecked.
    • state_checked-when object is checked.
    • state_enabled-when objects are enabled(are able to receive clicks or touch)
    • state_window_focused-when application window has focus means app comes in foreground.
  • Now in multistate_button.xml file we will use pressed, focused. so lets begin.
    • select MultistateButton project.
    • right click on drawable folder and click on new.
    • and write multistate_button.xml and then finish.

16 Dec 2012


Create Multistate Buttons For Layout In User Interface

Multistates buttons are useful for showing the various states of buttons like pressed,focussed,normal state. For creating multistate button in the layout we need to use two classes .
  • First one, android.graphics.drawable.StateListDrawable class,which creates a drawable objects to show different images on same graphics based on the state of objects.Here each graphics is represented by <item> elements inside single <selector> elements.
  • Second one, android.widget.ImageButton class.It display an button with image in background and can be pressed.IT changes color during different state of button like focused, pressed etc.
So lets begin the programming step by step:
  • first open the eclipse select File -> New -> Project.
Multistate 1
  • Then Select Android -> Android Application Project and then click next.
  • Now fill with following details:
    • Project name- MultistateButton
    • Application name-MultistateButton
    • package name-multistate.Button
    • Minimum required SDK- select android 3.0
    • tick on create custom laucher icon.
    • tick on create project in workspace.
Multistate  2
  • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
  • Now we will create Multistate button file name as multistate_button.xml .but before doing this let us know the different state of button.
    • drawable- must for showing the normal state image.must refer to the image.
    • state_pressed-when object is pressed(touched/clicked) ,by default remains  non-pressed .
    • state_focused-when object has input focussed(when user selects text input).
    • state_hovered-when object is hovered by cursor , very similar to focused state.
    • state_selected-when object are selected through directional control inside focused state.
    • state_checkable-when object is checkable.object should be a type of check or unchecked.
    • state_checked-when object is checked.
    • state_enabled-when objects are enabled(are able to receive clicks or touch)
    • state_window_focused-when application window has focus means app comes in foreground.

15 Dec 2012


Step By Step Set Margin In ViewGroups In User Interface

Margin provides space from the four side of screen area to ViewGroups.It can be set for any ViewGroup objects.Imp points about Margin:
  • It can only be set for ViewGroup objects not for View objects.
  • Margin class name is android.view.ViewGroup.MarginLayoutParams.
  • ViewGroups subclass include classes like Absolute Layout,Relative Layout,Grid Layout,Sliding Drawer,Grid view etc.
  • Margin can be set from four side left,top,right,bottom.
So lets look at this step by step:
  • first open the eclipse select File -> New -> Project.
Margin 1
  • Then Select Android -> Android Application Project and then click next.
  • Now fill with following details:
  • Project name- MarginExample
  • Application name-MarginExample
  • package name-margin.ViewGroups
  • Minimum required SDK- select android 3.0
  • tick on create custom laucher icon.
  • tick on create project in workspace.
    Margin 2

    • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
    • Now you have configured the Eclipse and ready to use MarginExample. Now select your project MarginExample and click on res ->layout ->activity_main.xml. 
    • After opening the activity_main.xml you will see the following code.

    14 Dec 2012


    Step By Step Set Padding In Views Of User Interface

    Padding provides space to the view so that view content don't touches the boundary of view.Padding can be added from the four side.
    Important points:
    • Padding are only meant for the View class or android.view.View.
    • Views subclass include class like Button,analog clock.image view,text view,calender view, scroll view etc.
    • Padding can be set from the four side left,top,right,bottom.
    So lets look at this step by step:
    • first open the eclipse select File -> New -> Project.
    Padding 1

    • Then Select Android -> Android Application Project and then click next.
    • Now fill with following details:
      • Project name- PaddingExample
      • Application name- PaddingExample
      • package name-padding.View
      • Minimum required SDK- select android 3.0
      • tick on create custom laucher icon.
      • tick on create project in workspace.
      Padding 2

      • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
      • Now you have configured the Eclipse and ready to use PaddingExample. Now select your project PaddingExample and click on res ->layout ->activity_main.xml. 
      • After opening the activity_main.xml you will see the following code.


      • Now in the above activity_main.xml file add one button view.so that final code look like this.
        1:   xmlns:tools="http://schemas.android.com/tools"  
        2:    android:layout_width="match_parent"  
        3:    android:layout_height="match_parent" >  
        4:    <TextView  
        5:      android:id="@+id/textView1"  
        6:      android:layout_width="wrap_content"  
        7:      android:layout_height="wrap_content"  
        8:      android:text="@string/hello_world"  
        9:      tools:context=".MainActivity" />  
        10:    <Button  
        11:      android:id="@+id/button1"  
        12:      android:layout_width="wrap_content"  
        13:      android:layout_height="wrap_content"  
        14:      android:layout_alignLeft="@+id/textView1"  
        15:      android:layout_alignParentTop="true"  
        16:      android:layout_marginTop="83dp"  
        17:      android:text="Button" />  
        18:  </RelativeLayout>  
        
        • Now we need to run this project before doing padding in button.
            • As you have already set up emulator for android.
              • so to compile right click on top level of project PaddingExample project folder in the package explorer and select run as ->android application.
                • The emulator will take approximately 30 sec then after it will launch your project in the emulator  environment.
                  • This is the view without Padding


                Padding 3

                13 Dec 2012


                Step By Step Create SlidingDrawer User Interface

                SlidingDrawer layout container is direct subclass of ViewGroup class.It expand the screen area which can be used by user interface components.It should be used as an overlay inside Layout.SLidingDrawer can be used horizontally or vertically.It is special widget composed of two child views .
                • First one is Handle,user drag.
                • Second one is Content,which is attached with the handle and dragged with it.
                so lets learn it step by step that how to use.
                • first open the eclipse select File -> New -> Project.


                Sliding Drawer
                • Then Select Android -> Android Application Project and then click next.
                • Now fill with following details:
                • Project name- SlidingDrawerExample
                • Application name- SlidingDrawerExample
                • package name-sliding.Drawer
                • Minimum required SDK- select android 3.0
                • tick on create custom laucher icon.
                • tick on create project in workspace.

                Sliding Drawer 2
                • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
                • Now you have configured the Eclipse and ready to use SlidingDrawer.Now select your project SlidingDrawerExample and click on res ->layout ->activity_main.xml. 
                • After opening the activity_main.xml you will see the following code.

                • Now you need to add SlidingDrawer inside Relative Layout so replace Textview with SlidingDrawer xml lines .therefore the finally activity_main.xml will look like this.
                1:  <?xml version="1.0" encoding="utf-8"?>  
                2:  <RelativeLayout  
                3:  xmlns:android="http://schemas.android.com/apk/res/android"  
                4:  android:layout_width="fill_parent"  
                5:  android:layout_height="fill_parent">  
                6:  <SlidingDrawer  
                7:  android:id="@+id/drawer"  
                8:  android:layout_width="320dip"  
                9:  android:layout_height="440dip"  
                10:  android:orientation="vertical"  
                11:  android:handle="@+id/handle"  
                12:  android:content="@+id/content">  
                13:  <ImageView  
                14:  android:id="@+id/handle"  
                15:  android:layout_width="48dip"  
                16:  android:layout_height="48dip"  
                17:  android:src="@drawable/icon" />  
                18:  <AnalogClock android:id="@+id/content"  
                19:  android:background="#D0A0A0"  
                20:  android:layout_width="fill_parent"  
                21:  android:layout_height="fill_parent" />  
                22:  </SlidingDrawer>  
                23:  </RelativeLayout>  

                11 Dec 2012


                Step By Step Create Relative Layout User Interface

                RelativeLayout container arranges all the user interface elements relative to each other in a single ViewGroup to achieve complex layout.It is also a direct subclass of ViewGroup class.so lets learn and code it step by step.

                • first open the eclipse select File -> New -> Project.

                Relative layout 1

                • Then Select Android -> Android Application Project and then click next.
                • Now fill with following details:
                  • Project name- RelativeLayoutExample
                  • Application name-RelativeLayoutExample
                  • package name-relative.layout
                  • Minimum required SDK- select android 3.0
                  • tick on create custom laucher icon.
                  • tick on create project in workspace.


                Relative layout 2

                • In Config Launcher Icon window click Next and finally choose Blank Activity in Create Activity window and the click Next and then Finish.
                • Now you have configured the Eclipse and ready to use RelativeLayout.Now select your project RelativeLayoutExample and click on res ->layout ->activity_main.xml. 
                • After opening the activity_main.xml you will see the following code.



                • Now you need to edit the given above code and add some new xml lines,so that final code look like this .
                  • add textview widget give id name as "textView"
                  • add EditText widget give id name as "editText"
                  • add Button widget give id name as "okButton"
                  • add Button widget give id naem as "cancelButton"
                  1:  <?xml version="1.0" encoding="utf-8"?>  
                  2:  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
                  3:  android:orientation="vertical"  
                  4:  android:layout_width="fill_parent"  
                  5:  android:layout_height="fill_parent"  
                  6:  >  
                  7:  <TextView                   
                  8:  android:id="@+id/textView"            
                  9:  android:layout_width="fill_parent"  
                  10:  android:layout_height="wrap_content"  
                  11:  android:text="Type here:" />  
                  12:  <EditText  
                  13:  android:id="@+id/editText"           
                  14:  android:layout_width="fill_parent"  
                  15:  android:layout_height="wrap_content"  
                  16:  android:layout_below="@+id/textView"      
                  17:   />    
                  18:  <Button  
                  19:  android:id="@+id/okButton"           
                  20:  android:layout_width="wrap_content"  
                  21:  android:layout_height="wrap_content"  
                  22:  android:layout_below="@+id/editText"    
                  23:  android:layout_alignParentRight="true"  
                  24:  android:layout_marginLeft="10dip"       
                  25:  android:text="OK"/>  
                  26:  <Button  
                  27:    android:id="@+id/cancel"  
                  28:  android:layout_width="wrap_content"  
                  29:  android:layout_height="wrap_content"  
                  30:  android:layout_toLeftOf="@+id/okButton"  
                  31:  android:layout_alignTop="@+id/okButton"  
                  32:  android:text="Cancel"/>  
                  33:  </RelativeLayout>  
                  

                  Translate