Reputation: 1398
I am trying to get an action bar within my android app to show up with icons. No matter what I do, I only see the overflow icon with a dropdown, while I want to see the Home and Logout icons next to each other on the action bar menu. I have read through most posts on SO for a solution but am unable to find a solution. Can anyone please help ?
Below is my code :
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);
}
How I want it to show up
Upvotes: 1
Views: 52
Reputation: 1006724
MainActivity extends Activity
This means that you are using the native action bar, not the backport offered by appcompat-v7
. In that case, replace the app:
prefixes in your menu resource with android:
, and you will have better luck.
Was googling for a solution and saw someone use it
That is surprising. Your question is the first time I have ever seen anyone use that theme. I didn't even know it existed until I looked it up as part of checking your question. Most likely, you will want to use more modern themes.
Upvotes: 1