I am trying to create a logout menu item in the top actionbar. I performed the following steps:
1) res > right click > new > android resource directory > resource type > menu > ok
2) right click on the newly created menu folder and selected new > file > main_menu.xml
3) Based from these docs https://developer.android.com/guide/topics/resources/menu-resource.html, I added the following xml in the main_menu.xml text view:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
</menu>
4) In the main_menu.xml design view, I dragged a menu item into the menu. I gave it an id, a title and showAsAction set to always. I then returned to text view and noticed the following generated:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Logout" android:id="@+id/@+id/logout" android:showAsAction="always"/>
</menu>
5) I fixed the id and noticed showAsAction it was giving the following message:
Should use app:showAsAction with appcompat library with xmlns:app="schemas.android.com/apk/res-auto"';
I ran the app and the menu item never showed up.
Didding through research, I changed the xml to this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="schemas.android.com/apk/res-auto">
<item android:id="@+id/action_settings" android:title="Logout"
android:orderInCategory="100" app:showAsAction="always"/>
</menu>
I even tried add this to the xml:
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
But the menu item is not showing up on the MainActivity screen.