Show dividers on menu
By default, the overflow menu does not support dividers between items. To show dividers on the overflow menu, add the following code:
1 2 3 4 5 6 7 8 9 10 11 12
override fun onCreateOptionsMenu(menu: Menu?): Boolean { val inflater = menuInflater inflater.inflate(R.menu.map_options, menu) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { menu?.setGroupDividerEnabled(true) } MenuCompat.setGroupDividerEnabled(menu, true) return true }
Lines 2~3 inflate the menu, while:
- 5️⃣ - If SDK version supports the divider, enable the .setGroupDividerEnabled
- 9️⃣ - Load MenuCompat to enable compatibility with lower versions of Android
The end result:
→