The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
If you have spent much time on an Android 3.0+ device, then you probably have run into a curious phenomenon. Sometimes, when you select an item in a list or other widget, the action bar magically transforms from its normal look:
Figure 479: Regular Action Bar for Activity with EditText
to one designed to perform operations on what you have selected:
Figure 480: Action Mode, Given Selected Word in EditText
The good news is that this is not some sort of magic limited only to
built-in widgets like
EditText. You too can have this effect in
your application, by triggering an “action mode”.
In this chapter, we will explore how you can set up and respond to action modes.
Understanding this chapter requires that you have read the core chapters, particularly the one on the action bar.
Most desktop operating systems have had the notion of a “context menu” for some time, typically triggered by a click of the right mouse button. In particular, a right-click over some selected item might bring up a context menu of operations to perform on that item:
Android supports context menus, driven by a long-tap on a widget rather than a right-click. You will find a few applications that offer such menus, particularly on lists of things. However, context menus are a very old UI design pattern in Android, and modern apps rarely use them.
Instead, contextual operations are raised via an action mode, so when
the user specifies a context (e.g., selects a word in an
the action bar changes to show operations relevant for the selection.
The preview of this section is presently indisposed.
The preview of this section was fed to a gremlin, after midnight.
The preview of this section may contain nuts.