-1

I was trying to show option menu in activity_main.xml App bar so I go in value folder and then create a menu and write this code in MainActivity.kt

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

If I run this application on device screen 5.0 then 3 dots show in Appbar and works fine but if I run this application on smaller screen like 4.0 inch or smaller then 5.0 so 3 dots menu not shows in Appbar but still working if I press menu button in softkeys. Why this menu goes out of screen on smaller screen. I think I am forgetting something to write or create.

Zoe
  • 27,060
  • 21
  • 118
  • 148

1 Answers1

1

Are the smaller screen devices on an Android version under KitKat? Older versions won't show the three-dot menu in the ActionBar by default, if they have either a hardware menu button or a software navigation bar with the ability to show the menu button.

It's also possible that a smaller screen might not have room to show the button in the ActionBar and still have the title and potential NavigationDrawer button elements show properly.

If you want to force it to show on all devices, read this. Basically, you'll need to add the following to your onCreate() method:

try {
    ViewConfiguration config = ViewConfiguration.get(this);
    Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
    if (menuKeyField != null) {
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
    }
} catch (Exception ignored) {
}

I seem to remember there being a theme attribute you can define in your AppTheme, but I can't find it.

TheWanderer
  • 16,775
  • 6
  • 49
  • 63