Hari Krishnan Hari Krishnan - 4 months ago 27
Android Question

How to hide menu elements in android?

I need to trigger a function on clicking the menu icon, and i don't need to show any items inside the menu. When i tries to avoid all the items inside the menu tag, the whole icon itself gets invisible. So how could i display only the menu icon and hide its sub items?

<?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/action_settings"
android:orderInCategory="100"
android:icon="@drawable/ic_menu_camera"
android:title="Settings"
app:showAsAction="never" />

//removing the above item removes the whole menu title icon.
</menu>

Answer

you need to change app:showAsAction="always", as below

<?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/action_settings"
        android:icon="@drawable/ic_menu_camera"
        android:orderInCategory="100"
        android:title="Settings"
        app:showAsAction="always" />
</menu >

check this https://developer.android.com/guide/topics/resources/menu-resource.html

Comments