图标未显示在操作栏中

Icons not showing up in Action bar

我正在尝试在我的 android 应用程序中添加一个操作栏以显示图标。无论我做什么,我只看到带有下拉菜单的溢出图标,而我想在操作栏菜单上看到彼此相邻的主页和注销图标。我已经阅读了关于 SO 的大多数帖子以寻求解决方案,但无法找到解决方案。有人可以帮忙吗?

下面是我的代码:

AndroidManifest.xml

<application
    android:name=".application.MySampleApplication"
    android:icon="@drawable/letter"
    android:label="My Sample"
    android:theme="@android:style/Theme.WithActionBar">

Menu_Main.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_logout"
        android:icon="@drawable/logout"
        android:title="@string/logout"
        android:orderInCategory="0"
        app:showAsAction="always" />
    <item
        android:id="@+id/action_home"
        android:title="@string/gohome"
        android:icon="@drawable/ulogo"
        android:orderInCategory="0"
        app:showAsAction="always" />
</menu>

MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_logout) {
        logout();
        return true;
    }
    if (id == R.id.action_home) {
        goHome();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

现在如何显示

我希望它如何显示

MainActivity extends Activity

这意味着您使用的是本机操作栏,而不是 appcompat-v7 提供的向后移植。在这种情况下,将菜单资源中的 app: 前缀替换为 android:,您的运气会更好。

Was googling for a solution and saw someone use it

真令人惊讶。您的问题是我第一次看到有人使用该主题。我什至不知道它的存在,直到我在检查你的问题时查找它。您很可能希望使用更现代的主题。