Reputation: 1509
I'm trying to display my menu in the action bar like this :
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/Menu1"
android:icon="@drawable/res1"
android:showAsAction="ifRoom"
android:title="Menu1"/>
<item
android:id="@+id/Menu2"
android:icon="@drawable/res2"
android:showAsAction="ifRoom"
android:title="Menu2"/>
<item
android:id="@+id/Menu3"
android:icon="@drawable/res3"
android:showAsAction="ifRoom"
android:title="Menu3"/>
</menu>
And in the code :
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_logged, menu);
return true;
}
On the design editor the buttons are shown. But when I launch the app on my smartphone (Samsung Galaxy Note 3) the 3 dots are shown with the menu inside it. But no menu in the Action Bar.
I don't understand, I tested all flags for android:showAsAction
and I still have the 3 dots with the menu inside.
Thanks for your help !
Upvotes: 0
Views: 48
Reputation: 2737
try below menu.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/Menu1"
android:icon="@drawable/ic_launcher"
app:showAsAction="ifRoom"
android:title="Menu1"
android:orderInCategory="0"/>
<item
android:id="@+id/Menu2"
android:icon="@drawable/ic_launcher"
app:showAsAction="ifRoom"
android:title="Menu2"
android:orderInCategory="1"/>
<item
android:id="@+id/Menu3"
android:icon="@drawable/ic_launcher"
app:showAsAction="ifRoom"
android:title="Menu3"
android:orderInCategory="2"/>
</menu>
Upvotes: 2
Reputation: 328
try using this
<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=".MainActivity">
<item
android:id="@+id/Menu1"
android:icon="@drawable/ic_launcher"
app:showAsAction="always"
android:title="Menu1"
android:orderInCategory="0"/>
<item
android:id="@+id/Menu2"
android:icon="@drawable/ic_launcher"
app:showAsAction="always"
android:title="Menu2"
android:orderInCategory="1"/>
<item
android:id="@+id/Menu3"
android:icon="@drawable/ic_launcher"
app:showAsAction="always"
android:title="Menu3"
android:orderInCategory="2"/>
</menu>
Upvotes: 2
Reputation: 16976
Try this:
<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=".MainActivity">
<item
android:id="@+id/Menu1"
android:icon="@drawable/res1"
android:title="Menu1"
app:showAsAction="ifRoom" />
<item
android:id="@+id/Menu2"
android:icon="@drawable/res2"
android:title="Menu2"
app:showAsAction="ifRoom" />
<item
android:id="@+id/Menu3"
android:icon="@drawable/res3"
android:title="Menu3"
app:showAsAction="ifRoom" />
</menu>
Also, take a look:
http://developer.android.com/guide/topics/resources/menu-resource.html
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@[+][package:]id/resource_name"
android:title="string"
android:titleCondensed="string"
android:icon="@[package:]drawable/drawable_resource_name"
android:onClick="method name"
android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]
Upvotes: 1
Reputation: 1516
import this
app xmlns:app="http://schemas.android.com/apk/res-auto"
and use this app:showAsAction="always"
in place of android:showAsAction="ifRoom"
Edited full Code
<menu xmlns:android="http://schemas.android.com/apk/res/android"
app xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/Menu1"
android:icon="@drawable/res1"
app:showAsAction="always"
android:title="Menu1"/>
<item
android:id="@+id/Menu2"
android:icon="@drawable/res2"
app:showAsAction="always"
android:title="Menu2"/>
<item
android:id="@+id/Menu3"
android:icon="@drawable/res3"
app:showAsAction="always"
android:title="Menu3"/>
</menu>
Upvotes: 3