Android系统中菜单分为Options Menu、Context Menu、Sub Men三种
Options Menu和Context Menu属于一级菜单
Sub Menu属于Options Menu和Context Menu的子菜单
Sub Menu下不能再添加菜单,Android最多只能支持两级菜单
选项菜单(Options Menu)在当前Activity中按下菜单键就会显示
Android4.0一下默认在屏幕底部(我也不知道我的为什么默认是在右上角!!!)
常用以下方法使用 选项菜单
onCreateOptionsMenu(Menu menu):创建菜单,会在菜单第一次显示时调用。
onPrepareOnptionsMenu(Menu menu): 准备显示菜单,菜单每次显示前调用。
onOptionsItemSelected(MenuItem item):菜单项被选中后处理选中的菜单项。
onMenuOpened(int featureId,Menu menu):菜单被打开的事件。
onOptionsMenuClosed(Menu menu):菜单被关闭的事件。
openOptionsMenu():调用打开菜单
closeOptionsMenu():调用关闭菜单
运行截图:
程序结构:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro>
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.example.asus.gary_03.MainActivity">
<EditText
android:id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="输入文字"
android:editable="false"
android:inputType="textPersonName" />
</LinearLayout>