【发布时间】:2018-04-27 08:01:43
【问题描述】:
我尝试使用像 Google 键盘 Gboard 这样的键盘将表情符号插入到我的 edittext,但它显示 toast This text field does not support GIF insertion from the keyboard。
有几个相同的问题,但没有正确的答案,。我读了documentation reference given,但没有给出实现。我试过了,但它没有触发onCommitContent -
EditText editText = new EditText(this) {
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
final InputConnection ic = super.onCreateInputConnection(editorInfo);
final InputConnectionCompat.OnCommitContentListener callback =
new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
int flags, Bundle opts) {
// read and display inputContentInfo asynchronously
if (BuildCompat.isAtLeastNMR1() && (flags &
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
}
catch (Exception e) {
return false; // return false if failed
}
}
// read and display inputContentInfo asynchronously.
// call inputContentInfo.releasePermission() as needed.
return true; // return true if succeeded
}
};
return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
}
};
但 Whatsapp、Telegram 等应用程序支持此功能。我需要创建自定义 EditText 吗?
【问题讨论】:
-
我认为你错过了
setmimetype。
标签: android android-edittext android-softkeyboard