The menu from Chromium Android appmenu(Github Mirror). It can do this:
Notice the press, move, selection, up are finished in one gesture.
I love this design. It significantly improves the efficiency of using an app. So I dig into chromium, extract related code and pack them into this library.
Update: Recently, I found that getDragToOpenListener provides a similar effect.
-
Install dependency
- JitPack:
implementation 'com.github.DeweyReed:ChromeMenu:0.2.0'
- JitPack:
-
Set up touch listener
val coordinator = AppMenuCoordinatorFactory.createAppMenuCoordinator( this, { binding.btn }, object : AppMenuDelegate { override fun onOptionsItemSelected(item: MenuItem, menuItemData: Bundle?): Boolean { onMenuItemClicked(item) return true } override fun createAppMenuPropertiesDelegate(): AppMenuPropertiesDelegate { return object : AbstractAppMenuPropertiesDelegate() { override fun getAppMenuLayoutId(): Int = R.menu.menu } } override fun shouldShowAppMenu(): Boolean = true }, window.decorView ) binding.btn.setOnTouchListener( coordinator.appMenuHandler.createAppMenuButtonHelper() )
-
Check the sample for more customization.
-
Change menu width
Add this line to
dimens.xml
:<!-- 256dp is the original width --> <dimen name="cm_menu_width">258dp</dimen>
-
0.2.0
- New usage
- Target Android SDK 34, Min Android SDK 21, AGP 8.3.2, AppCompat 1.7.0
-
0.1.1
- Pull changes from chromium
- fffabbc: IPH : Set focus to highlighted menu item after opening app menu
- ead7304: Add common colors in night- and some initial clean up on themes
- Add proguard rules #1.
- Pull changes from chromium
-
0.1.0
To set custom menu width, use
cm_menu_width
instead of the oldmenu_width
.