Development issue/problem:

I’m trying to create a custom menu, but that doesn’t work on a device with MIUI rom and Android 6. The result is a general menu with all items copied and selected. It works perfectly on other pure Android devices and simulators.


textViewTop.setCustomSelectionActionModeCallback(new android.view.ActionMode.Callback() {
@General Boolean Menu
onCareActionMode(android.view.ActionMode, menu) {

Log.d(LOG_TAG, onCreateActionMode) ;

return where;

@General Boolean menu
onPrereActionMode (Action mode, menu) {
Log.d(LOG_TAG, onPrereActionMode);
menu.clear() ;

int quote_quick = R.drawable.ic_desktop_mac_black_24dp ;
int quote_add = R.drawable.ic_computer_black_24dp ;
int copy = R.drawable.ic_devices_other_black_24dp ;

menu.add(Menu.NONE, QUOTE_START, 3, ).setIcon(quote_quick).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(Menu.NONE, QUOTE_ADD, 2, ).setIcon(quote_add).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(Menu.NONE, CUSTOM, 1, ).setIcon(copy).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
return false;

General Boolean
onActionItemClicked(ActionMode, MenuItem item) {
returns false;

@Override public void
toDestroyActionMode {


How can I solve this problem?

Solution 1:

A few thoughts. What happens if you take an item from the Recovery options menu and change it?

Here’s how:

public boolean onCreateOptionsMenu(final menu) {
getSupportMenuInflater().inflate(, menu);
new Handler().post( -> {
final View menuItemView = findViewById(;

Solution 2:

So I’ve found an alternative, but it only makes sense if it absolutely has to work on MIUI devices. It’s usually a little uncomfortable:

I noticed that the Wikipedia application has custom actions that work on the Xiaomi device, and after checking the code, I found that it works well when texts are selected in WebView.
You can mainly use WebView and replace OnActionModeStarted in your company.


String html = n +
n +
n +
n +
n +
n +
n +
n +
n +
n ;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout.activity_main) ;

WebView webView = findViewById(;
webView.setWebViewClient(new WebViewClient());
webView.loadData(html, text/html, UTF-8);

public void onActionModeStart(mode)) {
menu = mode.getMenu();
mode.getMenuInflater().inflate(, menu);

Menu :

Results :

Solution 3:

According to, you must create a menu in OnCreateActionMode.

I did it this way (in Kotlin):

Fall actionModeCallbackA = object : ActionMode.callback {
override fun onActionItemClicked(mode: ActionMode?, p1: MenuItem?): Boolean {, onActionItemClicked)
actionModeB = startActionMode(actionModeCallbackB)
return true

Skip the fun onCheatActionMode?, Menu?: Boolean { MODE, onCreateActionMode)
fall inflater = mode ?.getMenuInflater()
inflater ?.inflate(, menu)
return true

Skip the fun to OwnActionMode(p0: ActionMode?, p1: Menu?): Boolean { MODE, onPrepareActionMode)
returns false

Replace the fun in destruction mode (p0: ActionMode?) { MODE, onDestroyActionMode)
actionModeA = null

Solution 4:

I had a similar problem, maybe my solution will help someone. I had to create a view consisting of several EditTexts horizontally side by side, and add the ability to paste text (one letter of text in an EditText)
I used the ActionMode.Callback approach, and it worked well, except on Xiaomi devices. The solution for the Xiaomi devices was to use OnLongClickListener when editing text and to create a PopupMenu when a long click occurs:

editText.setOnLongClickListener(v -> {
PopupMenu menu = new PopupMenu(context,v);
MenuInflater inflater = menu.getMenuInflater();
inflater.inflate(, menu.getMenu()));
menu.setOnMenuItemClickListener(item -> {
pasteText();//een custom function to process the selected action
return false;
return true;

Good luck!

mi 10 features,miui 11,latest launch of redmi note series,miui 10 update download,miui 12 release date,miui 13,miui 10.3 3,what is miui forum,how long does xiaomi support their phones,miui phones,miui system,is miui open source,used com miui home,miui 7

You May Also Like

Fixing Windows 10 Won’t Play GoPro Videos

RECOMMENDED: Click here to fix Windows errors and optimize system performance. With…

Top 10 Robin William’s Movies List [2020 Updated]

Robin William’s acting career started in the late 1970s and he is…

How to set up a Minecraft server on Raspberry Pi? –

If you want to set up a Minecraft server on an old…

How to use Android phone as a computer gamepad

Unless they are first-person shooter games and similar games where the combination…