主页中带有设置菜单的操作栏未显示。如果我单击设置按钮,它只会显示在底部
My action bar with settings menu in the Homepage doesn't show. It only shows on the bottom if I click the settings button
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.liveupdate.app.HomepageActivity" >
<item android:id="@+id/updateStatus"
android:title="Update"
app:showAsAction="always" />
<item android:id="@+id/LogoutUser"
android:title="Logout"
app:showAsAction="never" />
</menu>
我错过了什么?当我按下左键时,设置仅显示在底部。是我选择的版本吗?因为我没有看到任何错误出现或类似的东西。请帮忙。
HomepageActivity 是否扩展了 ActionBarActivity(而不是 Activity)?
编辑:
检查主页Activity是否以:
开头
public class HomepageActivity extends ActionBarActivity {
....
}
如果不是(并且它扩展了 Activity),请修复它,您应该可以解决问题。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.liveupdate.app.HomepageActivity" >
<item android:id="@+id/updateStatus"
android:title="Update"
app:showAsAction="always" />
<item android:id="@+id/LogoutUser"
android:title="Logout"
app:showAsAction="never" />
</menu>
我错过了什么?当我按下左键时,设置仅显示在底部。是我选择的版本吗?因为我没有看到任何错误出现或类似的东西。请帮忙。
HomepageActivity 是否扩展了 ActionBarActivity(而不是 Activity)?
编辑:
检查主页Activity是否以:
开头public class HomepageActivity extends ActionBarActivity {
....
}
如果不是(并且它扩展了 Activity),请修复它,您应该可以解决问题。