Java 如何从actionbar设置启动任务/布局
因此,我启用了Java 如何从actionbar设置启动任务/布局,java,android,eclipse,menu,android-actionbar,Java,Android,Eclipse,Menu,Android Actionbar,因此,我启用了ActionBarsettings面板。我对main.xml进行了如下编辑 <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_about" android:orderInCategory="100" android:showAsAction="never"
ActionBar
settings面板。我对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>
但在应用程序中,我单击“关于”按钮。它什么也不做?那么如何启动它呢?覆盖
onOptionsItemSelected
。再次查看文档处理对操作项目的点击
引用
当用户按下某个操作时,系统将调用活动的
onOptions ItemSelected()方法。使用传递给此
方法,您可以通过调用getItemId()来标识该操作。这
返回由标记的ID属性提供的唯一ID,以便
可以执行适当的操作
问问题之前你看过文件了吗??。你是问上一个问题的同一个用户,你提到没有搜索文档的互联网速度很慢。对不起,我没有,我下次再看一看!打开新布局后,按“上一步”退出应用程序,如何使其返回主屏幕?@SmallVille open new layout??。你不能打开布局。您可以导航到不同的活动。张贴相同的代码。通过编辑您的问题并发布编辑标题,保留旧的part.nvm,我最终完成了您所述的操作-Intent I=newintent(getApplicationContext(),playlactivity.class);startActivityForResult(i,100);活动被添加到后台堆栈中。Activity1-->Activity2单击返回按钮导航到Activity1。因此,它不会退出app@SmallVille进一步阅读这篇文章
@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;
}
@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);
}
}