When you hold your finger on a
view
long enough,
a
ContextMenu
appears.
The context menu you get depends on which view you press;
In the above picture, I pressed the red
TextView.
The context menu appears at the center of the screen.
See
Creating
a Context Menu,
and the methods
registerForContextMenu,
onCreateContextMenu,
onContextItemSelected
of class
Activity.
The
Menu.NONE
as the first argument of
add
means that the
MenuItem
is not part of a
group.
The second and third arguments of
add
are the item id (unique; used in
onContextItemSelected)
and the order.
The fourth argument is a
CharSequence,
and
class
String
implements the interface
CharSequence.
I picked a
textSize
of 18
scaled
pixels
to agree with the text in the
ActionBar.
ContextActivity.java:
I created the menus here,
although I could also have created them in
.xml
files.R.javamain.xml:
three
TextViews
in a
LinearLayout:
red, green, blue.AndroidManifest.xml