Friday 28 February 2014

Actionbar in android 2.2 (Below Android 3.0 Version) Example - ActionBarSherlock Example

The action bar provides several key functions:
 

Provides a dedicated space for giving your app an identity and indicating the user's location in the app.

Makes important actions prominent and accessible in a predictable way (such as Search).

Supports consistent navigation and view switching within apps (with tabs or drop-down lists).


The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above.

Develop Application using ActionBar APIs in Above Android 3.0(API level 11) is Very Easy.ActionBar APIs Provides On wards Android 3.0(API level 11).

But How to if you run the same application on versions < 3.0 you won’t. Okay, It shows lot's of error messages and Application is crashed.

Then what is soultion for this issue ?


So, how do we get the ActionBar on pre-Honeycomb?using ActionBarSherlock this library does is that if you’re using your app in a device with Android 2.x, it gives you an ActionBar that is a copy of the real ActionBar (it behaves the same way), but if you’re on Android 3.0 or later, you’ll get the standard ActionBar .
The best thing is that the methods that you can use with this ActionBar are the same than with the standard one.
 
How to use ActionBarSherlock in Below Android 3.0 (API level 11) ?

Here are the steps to get the library into Eclipse:


First of all, go to Sherlock ActionBar library’s website(http://actionbarsherlock.com/) and Download the latest version (current is 4.0.0).

Then (unzip) open the file you downloaded, enter the root folder and you will see three folders: library, samples and website.

Extract the library folder into your work space folder. You can rename it if you want to something like “Sherlock-ActionBar-lib-4.0.0”.

Open Eclipse. Click File -> New -> Android Project.

Now select “Create project from existing source”, and select the folder that you copied into your work space folder.

You should also type a name such as “Sherlock-ActionBar-lib-4.0.0” :). Now press Next.
Select Android 4.1 as target SDK and press Finish.

Open the libs folder in the Project that we've created, right-click the “android-support-v4.jar” file and select Build Path -> Add to Build Path.

Now, we have the Android Library Project of the Sherlock ActionBar in our work space and in Eclipse.

Now create a  a new Android Project, targeting at least Android 4.1 SDK. We will call ActionBarSherlockExample with MainActivity Class.

Add Library(Sherlock-ActionBar-lib) project to ActionBarSherlockExample.

Steps for Adding (Sherlock-ActionBar-lib) to Current Project:

Select Project->Right click Select Properties from menu->Now Properties Dialog visible now select Android on (Left side panel)->Now you can see Is Add button to Add Library project to current project just select (Sherlock-ActionBar-lib) and add library project to current project and click on apply button.

Now Open your Activity(MainActivity.java)  which is created in current project.
 
public class MainActivity extends Activity {

}


Now Change extends Activity to SherlockActivity

See below code

public class MainActivity extends SherlockActivity {

}

Final Step ( Open the AndroidManifest of your ActionBarSherlockExample project and write inside the application tag just add below attribute)

android:theme="@style/Theme.Sherlock.Light.DarkActionBar"


Now you can run your current project in below 
 Android 3.0 (API level 11) version the you can see ActionBar .


Android Project:


Android Activity(MainActivity.java)

package com.androidsurya.actionbarsherlock;

import com.actionbarsherlock.app.SherlockActivity;
import android.os.Bundle;

public class MainActivity extends SherlockActivity {

      
@Override
      protected void onCreate(Bundle savedInstanceState) {
            
super.onCreate(savedInstanceState);
            setContentView(R.layout.
activity_main);
      }

}

AndroidManifest file

<?xml version="1.0" encoding="utf-8"?>
<
manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidsurya.actionbarsherlock"
    android:versionCode="1"
    android:versionName="1.0" >

    
<uses-sdk android:minSdkVersion="7" />

    
<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock.Light.DarkActionBar" >
        <activity
            android:name="com.androidsurya.actionbarsherlock.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                
<category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>









 

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...