0

I created a options menu in my toolbar which shows up with 3 dots icon. I has 2 problems. First, it's not looking like options menu in other apps (text misaligned) and when I run the app on phone it doesn't responds to touch, even the ripples don't show up. On the other hand options menu works when I run it in the emulator(Pixel 2 API 24)

options menu

Here's my MainActivity code:

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
    menuInflater.inflate(R.menu.options_menu, menu)
    return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
    return when (item.itemId) {
        R.id.option_about -> {
            Toast.makeText(this, "About", Toast.LENGTH_SHORT).show()
            return true
        }

        R.id.option_exit -> {
            Toast.makeText(this, "Exit", Toast.LENGTH_SHORT).show()
            return true
        }
        else -> super.onOptionsItemSelected(item)
    }
}

Here is the options_menu.xml

<?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/search"
        android:icon="@drawable/ic_search_primary"
        android:title="@string/search_title"
        app:actionViewClass="androidx.appcompat.widget.SearchView"
        app:showAsAction="collapseActionView|ifRoom" />

    <item
        android:id="@+id/option_about"
        android:title="About"
        app:showAsAction="never" />
    <item
        android:id="@+id/option_exit"
        android:title="Exit"
        app:showAsAction="never" />
</menu>
Amol Borkar
  • 2,321
  • 7
  • 32
  • 63
  • in your xml menu add all items in a group tag and remove showAsAction lines. your activity is ok but if not solved insert more code here – alireza daryani Dec 15 '19 at 05:59
  • check [this](https://stackoverflow.com/questions/28715765/what-is-orderincategory-in-actionbar-menu-item-why-it-is-use-for) – Mohammed Alaa Dec 15 '19 at 09:31

1 Answers1

0

Actually, I was using wrong popupTheme in my toolbar.

Amol Borkar
  • 2,321
  • 7
  • 32
  • 63