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():调用关闭菜单

 

运行截图:

Android_(菜单)选项菜单Android_(菜单)选项菜单Android_(菜单)选项菜单

程序结构:

Android_(菜单)选项菜单

 

 

<?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>
activity_main.xml

相关文章:

  • 2021-06-26
  • 2021-11-03
  • 2021-06-09
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2021-05-03
  • 2022-12-23
  • 2021-12-28
  • 2021-12-22
  • 2021-11-17
  • 2021-11-17
相关资源
相似解决方案