您好我会想你的问题提供答案
(”我可以创建一个按钮,模拟它的菜单按钮,然后写button.performClick(),所以它作为一个菜单按钮和菜单选项会看到“)
答:
步骤1 - 创建在布局按钮/图像按钮
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/a"
android:onClick="expand"
android:src="@drawable/button" />
在这里,我已经设置的onClick方法如在类MainActivity.java“扩展”
步骤2 - 现在定义你的“扩大”的方法,将用户一旦点击这个按钮,
public void expand(View v)
{
ImageButton imgButton=(ImageButton)findViewById(R.id.imageButton1) ;
imgButton.setVisibility(View.GONE);
openOptionsMenu();
}
,因为我希望按钮消失上调用这个代码,我设置的可视性“水涨船高”, CE菜单显示
步骤3 - * (如果你是设置按钮的可见性) *您也可以编写代码来设置可见为“可见”一旦菜单使用以下方法关闭
public void onOptionsMenuClosed(Menu menu) {
super.onOptionsMenuClosed(menu);
ImageButton imgButton=(ImageButton)findViewById(R.id.imageButton1) ;
imgButton.setVisibility(View.VISIBLE);
}
希望这会帮助你.....
我尝试openOptionsMenu()已经但它不起作用 – 2011-06-10 13:17:12
它显示错误,无法添加窗口标记null是无效的,你的活动runnig?虽然我的活动正常运行没有这条线 – 2011-06-10 13:23:03
是的我尝试两个,首先在onCreate(),然后在onResume(),但发生错误,应用程序意外停止,不可见 – 2011-06-10 13:32:03