Android菜单操作之创建并响应菜单

2019-12-10 18:16:53丽君

 android文档对onMenuItemClick(MenuItem item)回调方法的说明是"Called when a menu item has been invoked. This is the first code that is executed; if it returns true, no other callbacks will be executed." 可见该方法先于onOptionsItemSelected执行。

3.使用Intent响应菜单
第3种方式是直接在MenuItem上调用setIntent(Intent intent)方法,这样android会自动在该菜单被点击时调用 startActivity(Intent)。但是个人认为与其这样还不如直接在onOptionsItemSelected的case里手动调用 startActivity(Intent)来的直观。

结语

本文详细介绍了如何创建和响应选项菜单,下一篇《Android菜单操作之SubMenu和IconMenu》将继续介绍子菜单和图标菜单的使用,大家继续关注哦。



注:相关教程知识阅读请移步到Android开发频道。