Devices with Android + MIUI and setCustomSelectionActionModeCallback
So I figured out a workaround, but it makes sense only if you absolutely need it to work on MIUI devices. It's generally a little awkward:
I noticed that the Wikipedia app has custom actions working on a Xiaomi device, and after looking through the code I found out it works fine when the texts is selected in a WebView
.
You can basically use a WebView
and override onActionModeStarted
in your Activity
Acivity:
String html = "<!DOCTYPE html>\n" +
"<html>\n" +
"<head>\n" +
"</head>\n" +
"<body>\n" +
"\n" +
"<h1>WebView text</h1>\n" +
"\n" +
"</body>\n" +
"</html>\n";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.web_view);
webView.setWebViewClient(new WebViewClient());
webView.loadData(html, "text/html", "UTF-8");
}
@Override
public void onActionModeStarted(ActionMode mode) {
super.onActionModeStarted(mode);
Menu menu = mode.getMenu();
menu.clear();
mode.getMenuInflater().inflate(R.menu.menu_text_select, menu);
}
Menu:
<item android:id="@+id/id1"
android:title="miui"
app:showAsAction="ifRoom" />
<item android:id="@+id/id2"
android:title="has"
app:showAsAction="ifRoom" />
<item android:id="@+id/id3"
android:title="bugs"
app:showAsAction="ifRoom" />
<item android:id="@+id/id4"
android:title="D:"
app:showAsAction="ifRoom" />
Result: