30 Jan 2013


How to create Contextual Action Mode Menu in Android

Context Menus provides more flexibility and action which affects the specific item or a context frame in an user interface.It is available for any kind of view like ListView or GridView.
There are two ways of using Context Menus.
  1. Floating Context Menuvisit here for more details.
  2. Contextual Action Mode- This is a system implementation of action mode which displays contextual action bar at the top of screen with action items.Contextual Action Mode is available at Android 3.0(API 11) or higher version otherwise you need to use Contextual Floating Menus.
Context Menu thumbnail
Lets us begin programming for Contextual action Mode.
  • First open eclipse and start new project by selecting new-> file-> Android Application Project.
  • Then fill the following details in the project window.
    • Application Name-ContextualAction_Mode
    • Project Name-ContextualAction_Mode
    • Package Name- action_mode.contextual
    • Build SDK-Android 4.1(API 14)
    • and then click next and next and then finish.
Context Menu 1
  •  Now open activity_main.xml under menu folder in the project.

Context Menu 2
  •  In activity_main.xml of menu folder you will see the following lines in activity-main.xml .
  •  <menu xmlns:android="http://schemas.android.com/apk/res/android">  
       <item android:id="@+id/menu_settings"  
         android:title="@string/menu_settings"  
         android:orderInCategory="100"  
         android:showAsAction="never" />  
     </menu>  
    
  • Just replace the above lines with these new lines in activity_main.xml.
  •  <?xml version="1.0" encoding="utf-8"?>  
     <menu xmlns:android="http://schemas.android.com/apk/res/android" >  
       <item  
         android:id="@+id/action1"  
         android:title="@string/Menu1"  
       />  
       <item  
         android:id="@+id/action2"  
         android:title="@string/Menu2"  
       />  
       <item  
         android:id="@+id/action3"  
         android:title="@string/Menu3"  
       />  
     </menu>  
    
  • Now open activity_main.xml in layout folder of the project.
    • In the activity_main.xml of layout folder you will see the following lines.
    •  <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" >  
         <TextView  
           android:layout_width="wrap_content"  
           android:layout_height="wrap_content"  
           android:layout_centerHorizontal="true"  
           android:layout_centerVertical="true"  
           android:text="@string/hello_world"  
           tools:context=".MainActivity" />  
       </RelativeLayout>  
      
  • Just replace the above lines with these new lines in activity-main.xml.
  •  <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" >  
       <TextView  
         android:id="@+id/text_view"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:layout_centerHorizontal="true"  
         android:layout_centerVertical="true"  
         android:text="@string/hello_world"  
         tools:context=".MainActivity" />  
     </RelativeLayout>  
    
  • Now open strings.xml in values folder of the project.
    • In strings.xml of values folder you will the following lines.
    •  <resources>  
         <string name="app_name">ContextualAction_Mode</string>  
         <string name="hello_world">Hello world!</string>  
         <string name="menu_settings">Settings</string>  
         <string name="title_activity_main">MainActivity</string>  
       </resource  

19 Jan 2013


What is Lint in Android?

Lint is static code analysis android tools which checks the android project source file for errors and optimization improvements like security, correctness, performance, usability and accessibility.It is android scanning tools which identify and correct the structural quality of a code.
More about lint:

  • Its identifies and check that whether android application meet the functional requirement.
  • Lint tool has following part:
Lint
fig-lint tools processing ,src-developers.andriod.com

16 Jan 2013


How to run Lint from eclipse.

Lint is static code analysis android tools which checks the android project source file for errors and optimization improvements like security, correctness, performance, usability and accessibility.It is android scanning tools which identify and correct the structural quality of a code.
Lets us learn how run Lint from eclipse.
  • Select the project on which you want to apply lint.
  • After selecting the lint select the lint tool in eclipse( list tool exist at the top of eclipse.)
 Running the lint
  • Or the second method of running the lint is right click on project and select Android Tools->Run Lint:checks for common errors.
  • After selecting the lint tool you will see the lint Warning View

15 Jan 2013


How to create a Popup Menu in Android

In Android application, menus are the common user interface components which gives user a dynamic user experience. Popup menu is also a type of menu anchored to the view.When some event happens like click on button the it appear below the anchor view otherwise above the anchor view.Other details.
    • Popup menus are available after Android API 11 or higher.
    • They can be use for command giving or providing functionality to the user for some view.
popup menu
Now lets begin the programming for Popup Menu:
  • First start your eclipse and select new -> project and click next.
  • Now fill with following details:
  • Popup menu
    • Project name- PopupMenu
    • Application name- PopupMenu
    • package name-menu.popup
    • Minimum required SDK- select android 3.0
    • tick on create custom laucher icon.
    • tick on create project in workspace and then final.

14 Jan 2013


How to create a Checkable Popup Menu in Android

Checkable Menus provides more functionality to the menus by providing the option of checking the menu item. Popup menu is also a type of menu anchored to the view.When some event happens like click on button the it appear below the anchor view otherwise above the anchor view.Other details.
  • Popup menus are available after Android API 11 or higher.
  • They can be use for command giving or providing functionality to the user for some view.

popup menu
Now lets begin the programming for Popup Menu:
  • First start your eclipse and select new -> project and click next.
  • Now fill with following details:
  • popup menu
    • Project name- PopupMenu
    • Application name- PopupMenu
    • package name-menu.popup
    • Minimum required SDK- select android 3.0
    • tick on create custom laucher icon.
    • tick on create project in workspace and then final.
  • Now open the activity_main.xml layout under the res-> menu-> activity_main.xml and the replace the given code with this new code given below.
  •  <menu xmlns:android="http://schemas.android.com/apk/res/android">  
      <group android:checkableBehavior="single">  
         <item android:id="@+id/facebook"   
           android:title="facebook" >  
         </item>  
         <item android:id="@+id/wordpress"   
           android:title="wordpress">  
         </item>  
         <item android:id="@+id/google"  
            android:title="google">  
         </item>  
         </group>  
       </menu>  
    
  • Now open the activity_main.xml layout under the res-> layout-> activity_main.xml and the replace the given code with this new code given below.
     <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" >  
       <Button  
         android:id="@+id/button1"  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:layout_centerHorizontal="true"  
         android:layout_centerVertical="true"  
         android:onClick="showPopup"  
         android:text="Select Website" />  
     </RelativeLayout>  

13 Jan 2013


How to change Style of View in Android

Style is a collection of property provides format and look to view or Window.Although style can done only to a particular view or window.However to apply same style to whole application or activity you need to use a theme.
Style in Android is defined in xml file name as style.xml different from the layout xml file.

Style thumbnail

So lets us learn how to apply style to a view.
  • first start eclipse and select new-> file-> android application project.
  • fill the android application project with the following details:
    • Application name-StyleTheme
    • Project name-StyleTheme
    • Package name-style.theme
    • Build SDK-4.1(API-16)
Style Image
  • Now open activity_main.xml file under res-> layout-> activity_main.xml you will see the given code.
  •  <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" >  
       <TextView  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:layout_centerHorizontal="true"  
         android:layout_centerVertical="true"  
         android:text="@string/hello_world"  
         tools:context=".MainActivity" />  
     </RelativeLayout>  

11 Jan 2013


Learn How to Inherit Style properties in Android.


Style is a collection of property provides format and look to view or Window.Although style can done only to a particular view or window.However to apply same style to whole application or activity you need to use a theme.
Inheritence in Style allows to apply more attribute to the view.
Style in Android is defined in xml file name as style.xml different from the layout xml file.
Thumbnail-Inheritence style

So lets us learn how to apply style to a view.
  • first start eclipse and select new-> file-> android application project.
  • fill the android application project with the following details:
    • Application name-StyleTheme
    • Project name-StyleTheme
    • Package name-style.theme
    • Build SDK-4.1(API-16)
Style Image
  • Now open activity_main.xml file under res-> layout-> activity_main.xml you will see the given code.
  •  <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" >  
       <TextView  
         android:layout_width="wrap_content"  
         android:layout_height="wrap_content"  
         android:layout_centerHorizontal="true"  
         android:layout_centerVertical="true"  
         android:text="@string/hello_world"  
         tools:context=".MainActivity" />  
     </RelativeLayout>  

  • here we have defined properties for the text view individually .Instead of doing this we can use simply apply style for the view by writing these lines.
  •  <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" >  
       <TextView  
        style="@style/myStyle"  
         android:text="@string/hello_world" />  
     </RelativeLayout>  
    

Translate