How to Ceate Exit Icon in TitleBar Or Label Name in Android

426 Views Asked by At

I want to put an exit icon or log out button near the label name or title bar, so if I am anywhere in my application I can get back to the main menu. I have searched similar question at Stackoverflow but don't understand the answers. Perhaps the problem is I'm new to Android programming

Could someone explain how to do this?

1

There are 1 best solutions below

1
On

In your xml you have to add the button like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/new_game"
          android:icon="@drawable/ic_new_game"
          android:title="@string/new_game"
          android:showAsAction="ifRoom"/>
</menu>

The android:icon will fix it.