代码无误,为什么Menu菜单显示不了

英俊潇洒的王先生 2012-03-20 01:55:16
activity.java
package your.mypackage.namespace;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class WangActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public boolean onCreatOptionMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0,0,0,R.string.app_about);
menu.add(0,1,0,R.string.str_exit);
return true;
}

public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case 0:
openOptionDialog();
break;
case 1:
finish();
break;
}
return true;
}

private void openOptionDialog()
{
new AlertDialog.Builder(this)
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setPositiveButton(R.string.str_ok,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{

}
}
)
.show();
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@+drawable/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
</LinearLayout>
...全文
115 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ihrthk 的回复:]
怎么没人回呢,我来。。
注意这个onCreatOptionMenu方法,有拼写错误哦,应该是onCreateOptionsMenu,应该是重写Activity这个方法,详细原因你懂得。
在Eclipse重写方法最好使用快捷键,即快,又不容易出错。(1.选中要重写的类,2.按shift+alt+s,3.选择重写/覆盖方法,4.选择要重写的方法就可以了)
[/Quote]用快捷键重写,找不到onCreateOptionsMenu这个方法,所以菜单还是显示不出来
小裴同学 2012-03-20
  • 打赏
  • 举报
回复
哈哈,对头,重写还是ALT+/吧
ihrthk 2012-03-20
  • 打赏
  • 举报
回复
怎么没人回呢,我来。。
注意这个onCreatOptionMenu方法,有拼写错误哦,应该是onCreateOptionsMenu,应该是重写Activity这个方法,详细原因你懂得。
在Eclipse重写方法最好使用快捷键,即快,又不容易出错。(1.选中要重写的类,2.按shift+alt+s,3.选择重写/覆盖方法,4.选择要重写的方法就可以了)

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧