OptionMenu为整个应用程序在Android中? [英] OptionMenu for whole App in Android?

查看:114
本文介绍了OptionMenu为整个应用程序在Android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以创建一个选项菜单的一个活动。但现在我想创造一个应该适用于所有活动中的应用程序菜单中的退出选项。是否有创建一个选项菜单,一旦某个应用程序的可能的方式是什么?

I can create an Option Menu for a single Activity. But now I want to create a Logout option in the menu which should be available on all Activities in the App. Is there a possible way to create an Option menu once for an Application?

推荐答案

我在SO回答此一次,但我忘了在哪里......所以在这里我又来了。

I answered this once on SO, but i forgot where...so here i go again.

它非常简单。

创建一个 BaseActivity (扩展活动)。实现所有的选项菜单code本。重写你的 onOptionsMenu 等等...

Create a BaseActivity (extends Activity). Implement all your Options Menu Code in this. Override your onOptionsMenu,etc...

现在,为了你的所有其他活动,而不是延长活性,延长 BaseActivity 。你最终会得出所有的选项菜单code ......漂亮吧?

Now, For all your other Activities, instead of extending Activity, extend BaseActivity. You'll end up deriving all the options menu code...nifty eh?

code一次,多次使用...

Code once, use multiple times...

OOP为赢!

编辑:WarrenFaith指出的那样,你需要创建 BaseListActivity BaseMapActivity 如果你使用 ListActivity MapActivity

As WarrenFaith points out, you'll need to create BaseListActivity and BaseMapActivity if you're using ListActivity and MapActivity.

这篇关于OptionMenu为整个应用程序在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆