AndroidStudio : Adding a MenuBar / ActionBar to our apps.

AndroidStudio : Adding a MenuBar / ActionBar

The app bar, also known as the action bar, is one of the most important design elements in your app’s activities, because it provides a visual structure and interactive elements that are familiar to users. Using the app bar makes your app consistent with other Android apps, allowing users to quickly understand how to operate your app and have a great experience. The key functions of the app bar are as follows:

  • A dedicated space for giving your app an identity and indicating the user’s location in the app.
  • Access to important actions in a predictable way, such as search.
  • Support for navigation and view switching (with tabs or drop-down lists).

First we are going to see how to add a menu bar for versions lower than 3.0, after this we will learn about ActionBars.

When the user user the menú , a new activity will display and show info about our app.

Code here : https://github.com/RayRT/AndroidStudio-ActionBar-MenuBar

First step , crate a new project :

Now , create a new .xml resource File>New>Android resource file, with the File name : “menu_main” and resource type : Menu.

Replace the content :

Every menu works same, a title , id and a icon . You can add more properties if you want.

Well, we have our menu, now we need a new activity for launch this menu, create a new java class  “aboutActivity” and replace the code.

 

So we have our menu and our activity for launch with the dialog window  .The last step : go to main class and implement methods , onCreateOptions and onOptionsItemSelected.

As usual we use a Intent method to swich activities:

 

 

Our new menu should looks like this:

 

Since 3.0 we can use ActionBars instead MenuBars, replace code of menu_main.xml and run the app:

Looks our new ActionBar:

 

 

Resources :

https://developer.android.com/training/appbar/index.html

https://developer.android.com/training/appbar/setting-up.html

 

Acerca del autor: Start2Develop

Dejar una contestacion

Tu dirección de correo electrónico no será publicada.