Skip to main content

Introduction to Menus


Menus been to lots of changes in android. We will study everything old and new of this API 🙂+
Options Menu
 +
In this chapter you will learn,+
  • Create an options menu
  • Place Action items on the Action Bar
  • Create a Context menu
  • Create a Popup menu

There are three types of menus we can create in Android.

1. Options menu and app bar

The options menu is the primary collection of menu items for an activity. It’s where you should place actions that have a global impact on the app, such as “Search,” “Compose email,” and “Settings.”+

2. Context menu and contextual action mode

A context menu is a floating menu that appears when the user performs a long-click on an element. It provides actions that affect the selected content or context frame.The contextual action mode displays action items that affect the selected content in a bar at the top of the screen and allows the user to select multiple items.+

3. Popup menu

A popup menu displays a list of items in a vertical list that’s anchored to the view that invoked the menu. It’s good for providing an overflow of actions that relate to specific content or to provide options for a second part of a command. Actions in a popup menu should not directly affect the corresponding content—that’s what contextual actions are for. Rather, the popup menu is for extended actions that relate to regions of content in your activity.+
+
Important Note :+
Beginning with Android 3.0 (API level 11), Android-powered devices are no longer required to provide a dedicated Menu button.
The Action Bar and popup menus have only been available since Android 3.0.+

Defining a Menu in XML

For all menu types, Android provides a standard XML format to define menu items. Instead of building a menu in your activity’s code, you should define a menu and all its items in an XML menu resource. You can then inflate the menu resource (load it as a Menu object) in your activity or fragment.+
Using a menu resource is a good practice for a few reasons:+
  • It’s easier to visualize the menu structure in XML.
  • It separates the content for the menu from your application’s behavioral code.
  • It allows you to create alternative menu configurations for different platform versions, screen sizes, and other configurations by leveraging the app resources framework.
In next lesson will start creating an Options Menu for ActivityNavigator activity using xml and again we create the same at runtime.

Comments

Popular posts from this blog

web2apk

http://web2apk.com/create.aspx Create App   Intro   About   Changes   MalWare ?   Contact   Privacy Useful Links Bluetooth Mini Keyboards Android Mini PC Reset Android URL App Title Icon or

Android Bar Chart Using MpAndroidChart Library Tutorial

https://www.numetriclabz.com/android-bar-chart-using-mpandroidchart-library-tutorial/ Android Bar Chart Using MpAndroidChart Library Tutorial Objective In this tutorial we learn how to implement Bar Chart using MpAndroidChart Library in your Android App. Download Source Code       Step 1 Contents ·        1  Introduction ·        2  Creating Bar chart o    2.1  Create a new Project o    2.2  Adding library in Project o    2.3  Create Layout o    2.4  To Plot Bar Chart §   2.4.1  Initialize the graph id §   2.4.2  Creating a Dataset §   2.4.3  Defining X-axis labels §   2.4.4  Set the data §   2.4.5  Add the description to the chart §   2.4.6  Run your App § ...

how to retrieve image from sqlite database in android and display in listview

 Android platform provides several ways to store data in our application. 1. SQLite database 2. SharedPreferences etc For our post, we will only work with SQLite database. First and foremost, we need to understand what an SQLite database is? SQLite database  is an open source SQL database that stores data to a text file on a device. It executes SQL Commands to perform a set of functions, that is, create, read, update and delete operations. On my previous post, I showed how to  store data in SQLite database from edit text, retrieve and populate it in a listview . For this post, I will show the SQLite CRUD operations with images from gallery and text from EditText. We need to understand this; images are stored in SQLite database as BLOB data type. A BLOB is a large binary object that can hold a variable amount of data.  Note, we can only store images in the database as BLOB data type. We need to convert our image path to a bitmap th...