Overview
Some useful links are given below to start programming in Android applications.
- Android Programming - Day One
- Android Programming - Day Two
- How To Display A Dialog Windows In Android
- How To Display A Progress Dialog Window In Android
- Intent In Android
- Return Data Using Intent Object In Android Applications
- Passing Data Using An Intent Object In Android Applications
- Fragments In Android Applications
- Adding Fragments Dynamically In Android Application
- Fragment Life Cycle In Android Application
- Interaction Between Two Fragments
- Calling In Built Functions in Android Application
- Intent Object and Intent Filters in Android Application
- Displaying Notifications in Android Applications
- User Interface in Android Applications
- Orientation, Anchoring, Resizing And Repositioning Of Views In Android Application
- Activity Behavior When Screen Orientation Changes in Android Application
- Persevere with State Information during Changes in Configuration
- Detect Orientation Changes and Controlling the Orientation of the Activity
Introduction
In this article, you will learn about action bar, which is used in Android applications. The action bar displays the application icon together with the activity title. On the right side of the action bar, there are action items.
Implementation
Create a new project by selecting File->New->New Project.

Now, debug the application by pressing F11 on the Android emulator. Action bar located at the top of the screen will appear, which actually contains the application icon and the application name “ActionBarApp”.

If you want to hide the action bar, you need to add the line display given below in bold in the AndroidManifest.xml file.
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.administrator.actionbarapp" >
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".MainActivity"
- android:label="@string/app_name"
- android:theme ="@android:style/Theme.Holo.NoActionBar">//line to hide action bar.
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
Add the code given below in the styles.xml.
- <resources>
- <!-- Base application theme. -->
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
- <item name="android:windowNoTitle">false</item>
- <item name="android:windowActionBar">true</item>
- <!-- Customize your theme here. -->
- </style>
- </resources>
Modify the code in the onCreate() method to hide the ActionBar.
- protected void onCreate(Bundle savedInstanceState) {
- //getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ActionBar actionBar = getActionBar();
- actionBar.hide();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
Debug the Application and you will see the result.

Now, we see how to add action items to the action bar. Action items are the shortcut to some of the commonly performed operations in the Application. A student registration application can have some action items such as “Add New Student”, “Update Student Info”, “Delete Student Info” etc.
Modify the noCreateOptionsMenu() method.
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- //getMenuInflater().inflate(R.menu.menu_main, menu);
- super.onCreateOptionsMenu(menu);
- CreateMenu(menu);
- return true;
- }




Purushottam RathorePosted Jan 20, 2017, 3:59 AM
Nice article for beginner. how could I start learn android.