Devices with Android + MIUI and setCustomSelectionActionModeCallback

前端 未结 4 1680
迷失自我
迷失自我 2021-02-04 23:54

I\'m trying to create custom selection menu but it does not work on a device with rom MIUI and Android 6. The result is common menu with copy and select all

4条回答
  •  失恋的感觉
    2021-02-05 00:18

    According to https://developer.android.com/guide/topics/ui/menus#CAB you need to create menu in onCreateActionMode.

    I made it like this (in kotlin):

        val actionModeCallbackA = object : ActionMode.Callback {
        override fun onActionItemClicked(mode: ActionMode?, p1: MenuItem?): Boolean {
            Log.wtf("ACTION MODE", "onActionItemClicked")
            actionModeB = startActionMode(actionModeCallbackB)
            return true
        }
    
        override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
            Log.wtf("ACTION MODE", "onCreateActionMode")
            val inflater = mode?.getMenuInflater()
            inflater?.inflate(R.menu.context_menu, menu)
            return true
        }
    
        override fun onPrepareActionMode(p0: ActionMode?, p1: Menu?): Boolean {
            Log.wtf("ACTION MODE", "onPrepareActionMode")
            return false
        }
    
        override fun onDestroyActionMode(p0: ActionMode?) {
            Log.wtf("ACTION MODE", "onDestroyActionMode")
                actionModeA = null
        }
    }
    

提交回复
热议问题