I'm trying to show a map icon downloaded from the official android developers source.
I did everything as it should, but the icon won't show.
Here is my xml file named main_activity_bar
:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/mapIcon"
android:icon="@drawable/ic_action_map"
android:title="@string/mapIconTitle"
android:showAsAction="always"
/>
</menu>
Here is the main activity xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gs.testApp.MainActivity"
tools:ignore="MergeRootFrame" />
and this is what I have in the java class:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater actionMenue = getMenuInflater();
actionMenue.inflate(R.menu.main_activity_bar, menu);
return super.onCreateOptionsMenu(menu);
}
Everything seems to be fine, but the icon wont show on the emulator. Here is a screenshot:
The minimum version is android 3.0
Why the icon is not showing? What Am I missing? I know that it is something really small, but I can't spot it.
I dont think an icon is shown in the overflow menu. Try changing your title to "t" or rotate the screen. See if the icon appears this way.
Here is how I fixed it - in case that someone is facing the same issue.
I changed
android:showAsAction="always"
toapp:showAsAction="always"
and I also placed the icon orderandroid:orderInCategory="0"
and the auto resxmlns:app="http://schemas.android.com/apk/res-auto"
so now my xml looks like: