Android Action Bar Tutorial – The Ultimate Guide To Learn

0
318
android action bar

Android ActionBar Tutorial:

The action bar tutorial is about how to implement an ActionBar with Search widget, Help widget, Refresh widget in Android application.

ActionBar is used for adding widgets to action bar like search, refresh, sharing and many more actions plus navigation between screens drop-down & tabbed navigation and much more.

Basic about Action Bar:

It mainly contains four functional areas.

  • App icon
  • View Control
  • Action Buttons
  • Action Overflow.

Mainly Action bar have 4 parts of functions.
Action Buttons, App Icon, View Control (app title), Action Overflow
Here we are going to show that how to implement ActionBar with toast message by clicking on widget in ActionBar.

Create a new project in Eclipse

File > New > Android Application Project.
Application Name : ActionBar
Project Name : ActionBar
Package Name : com.adroittec.actionbar

CODE FOR: activity_main.xml

CODE FOR: activity_search.xml

CODE FOR: activity_help.xml

First, Copying required icons in drawable folder for action bar.

Now Create a new xml file under res -> menu named main_menu.xml and add the following code.

<item> indicates each action item. We are going to define 3 widget in actionbar.

Here ” android:actionViewClass=“android.widget.SearchView”” is provide default icon of search.

CODE FOR: main_menu.xml

Create a searchable configuration file under res -> xml folder named searchable.xml

Always assign the values of android:hint and android:label

CODE FOR: searchable.xml

CODE FOR: MainActivity.java

In Search_Activity.java

String query=intent.getStringExtra(SearchManager.QUERY);
tv1.setText(“Search Query” +  query);
Toast.makeText(getApplicationContext(), query,    Toast.LENGTH_LONG).show();

Use this query to display search results like

  1. Getting the data from SQLite and showing in listview
  2. Making webrequest and displaying the data

For now we just display the query only.

CODE FOR: Search_Activity.java

In AndroidManifest.xml file define the searchable configuration, default searchable activity and the activity performing the search.
Default searchable activity handle search- android.app.default.searchable
Searchable configuration which was written in searchable.xml- android.app.searchable
Intent filter for the activity which receives search query – android.intent.action.SEARCH

CODE FOR: AndroitManifest.xml

Finally, Run On Emulator/Device and see the output.

android action bar

android action barandroid action bar

 

 

 

 

 

 

 

FOR ANY QUERY OR SUGGESTION PLEASE COMMENT BELOW!!..

LEAVE A REPLY