gpt4 book ai didi

java - 如何从操作栏设置启动任务/布局

转载 作者:行者123 更新时间:2023-12-01 13:09:13 24 4
gpt4 key购买 nike

所以我启用了 ActionBar 设置面板。我已将 main.xml 编辑为如下所示。

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_about"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/about_one"
android:actionLayout="@layout/about"/>
</menu>

我的MainActivity实现 -

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

但是在应用程序中,我单击“关于”按钮。它什么也没做?那么我怎样才能让它启动呢?

最佳答案

覆盖onOptionsItemSelected。再次查看文档处理操作项的点击

http://developer.android.com/guide/topics/ui/actionbar.html

引用

When the user presses an action, the system calls your activity's onOptionsItemSelected() method. Using the MenuItem passed to this method, you can identify the action by calling getItemId(). This returns the unique ID provided by the tag's id attribute so you can perform the appropriate action

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_about:
// do something
return true;

default:
return super.onOptionsItemSelected(item);
}
}

关于java - 如何从操作栏设置启动任务/布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23026264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com