I have the same problem as posted many times like here or here. I define a menu item which shows up in the preview in AndroidStudio
:
But when I run the app on my phone the icon (a png
image) is not visible, and there is a lot of space available. However, this 'Add' option shows up in the Options menu (to the very right; together with 'Srttings'). Here is my menu.xml
:
<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/action_favourite"
android:icon="@mipmap/ic_add"
android:title="@string/menu_add"
android:showAsAction="always"/>
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
I tried the suggestions I could find, but none of them solved my problem. My phone is a LG G3. How can I solve this problem?
Additional information: onCreateOptionsMenu
@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;
}
Just use app:showAsAction="always"
and xmlns:app="http://schemas.android.com/apk/res-auto"
then it will show.
<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/action_favourite"
android:icon="@mipmap/ic_add"
android:title="@string/menu_add"
app:showAsAction="always"/>
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
You're probably using the support library which is dependent on the app namespace. If in doubt, just add the same property twice (android:
and app:
namespaces).
In onCreate()
add setHasOptionsMenu(true)
And you are probably inflating the wrong menu file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With