Devices with Android + MIUI and setCustomSelectionActionModeCallback

前端 未结 4 1730
迷失自我
迷失自我 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条回答
  •  萌比男神i
    2021-02-05 00:36

    I had similar problem, maybe my solution would help someone. I had to make a view composed of several horizontal neighboring EditText's, and add ability to paste text to them (one letter of text to one editText) I used ActionMode.Callback's approach and it was working fine, except Xiaomi devices. The solution for Xiaomi devices was using OnLongClickListener on edit texts and create PopupMenu on long click:

    editText.setOnLongClickListener(v -> {
        PopupMenu menu = new PopupMenu(context,v);
        MenuInflater inflater = menu.getMenuInflater();
        inflater.inflate(R.menu.paste_menu_item, menu.getMenu());
        menu.setOnMenuItemClickListener(item -> {
           pasteText();//some custom function to handle selected action
           return false;
        });
        menu.show();
        return true;
    });
    

提交回复
热议问题