android开发步步为营之29:选项菜单OptionsMenu的用法

菜单也是一个非常常用的主键,点击手机上的菜单按钮就呼出了。在Android中,菜单被分为如下三种,选项菜单(OptionsMenu)、上下文菜单(ContextMenu)和子菜单(SubMenu),今天这讲是OptionsMenu 
public interface  Menu
 
android.view.Menu
Known Indirect Subclasses
ContextMenu, SubMenu
ContextMenu Extension of Menu for context menus providing functionality to modify the header of the context menu.
SubMenu Subclass of Menu for sub menus.
 
 
Class Overview
Interface for managing the items in a menu.
 
By default, every Activity supports an options menu of actions or options. You can add items to this menu and handle clicks on your additions. The easiest way of adding menu items is inflating an XML file into the Menu via MenuInflater. The easiest way of attaching code to clicks is via onOptionsItemSelected(MenuItem) and onContextItemSelected(MenuItem).
 
Different menu types support different features:
 
Context menus: Do not support item shortcuts and item icons.
Options menus: The icon menus do not support item check marks and only show the item's condensed title. The expanded menus (only available if six or more menu items are visible, reached via the 'More' item in the icon menu) do not show item icons, and item check marks are discouraged.
Sub menus: Do not support item icons, or nested sub menus.
      开始我们的练习:创建一个OptionsMenu菜单
第一步、设计界面menuview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android=" http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TextView android:layout_height="wrap_content" android:text="点击menu键选择菜单
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值