Today in this article I will discuss and implement ActionBarSherlocka. First we need to Know about ActionBarSherlocka. Then we are going to start implement process using the android studio.

What is ActionBarSherlocka ?

ActionBarSherlock is an extension of the support library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.

The library will automatically use the native action bar when appropriate or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android from 2.x and up.


ActionBarSherlocka

Add Using Android Studio

In Android Studio, you might do it the Graphical user interface (GUI way).


Press CTRL+ALT+SHIFT+S
Select the module
Click Dependencies


ActionBarSherlocka

Click the green arrow
Select 1 Maven dependency
If you don’t know actual full name of actionbersherlock simple Input sherlock and press enter to search
Wait few moment Maven Look up your search then finally you will see
Select com.actionbarsherlock:actionbarsherlock:4.4.0@aar
Click OK


ActionBarSherlocka

This will automatically add it to your build.gradle
Now open your build.gradle File and see the actionbarsherlocka add as dependencies.

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
}

Importing Action Bar Sherlock Library to your Project

Open the Action Bar Sherlock Library you have downloaded earlier and extract it somewhere (for example to your ( C:UsersaamsuzonDownloads ). After extraction, the directory should look like this:


ActionBarSherlocka

Copy the directory called “actionbarsherlock” to your project root directory. After copying, your project root directory should look like this:


ActionBarSherlocka

Now we need to modify the settings.gradle to tell Gradle that we have to include another project on our build. settings.gradle is located on your project root ( YourApplicationProject/settings.gradle ).

Let us include the actionbarsherlock directory in your:settings.gradle

 include ':YourApplication', ':actionbarsherlock'

Now your Gradle is ready to compile. But before you can start coding, we need to configure Android Studio and tell about the library.

Adding Action Bar Sherlock library to Android Studio

Press CTRL+ALT+SHIFT+S
Select the module
Click Dependencies
Click the green arrow
Select  Module Dependency
Select the actionbarsherlock and then click Apply then OK to quit the Project Structure. Restart again the Android Studio.

You can now start coding your project using the Action Bar Sherlock.

Testing the Action Bar Sherlock

Open MainAcitivity.java File in your project. Import this line

import com.actionbarsherlock.app.SherlockActivity;

Now  let’s change the activity to sherlockactivity. We need to remove the onCreateOptionsMenu override method as this does not exist.

package com.example.yourapplication;

import android.os.Bundle;
//import android.app.Activity;
//import android.view.Menu;

import com.actionbarsherlock.app.SherlockActivity;

public class MainActivity extends SherlockActivity {

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

/* @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}*/

}

Almost done!! now we just need to modify the AndroidManifest.xml of our application to change the theme to the Action Bar Sherlock library themes.

To Action Bar Sherlock Light dark theme apply add this line

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

Your application will now able to run the Action Bar Sherlock library

If you face any problem to do this please write a comment.or if you have any others way to easily use the lib then write comment here

Leave a Reply

avatar
  Subscribe  
Notify of