Android : 如何在表情符号的软键盘顶部添加子视图?
Android : How to add child view on top of Softkeyboard for Emoji?
我想使用 EmojiView 在键盘顶部添加一个带有 EmojiView 的视图。现在我想要功能,就像当我为 EmojiView 键入任何主要代码时一样。我想在软键盘上显示一个 EmojiView。意思是从自己的视图中添加 pick 作为键盘的子视图。
我该怎么做?
感谢提前。请分享您的代码..
您可以使用 PopupWindow,它显示在软键盘的顶部。
看看https://github.com/ankushsachdeva/emojicon
在您的项目中添加库并使用以下代码:
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
popupWindow = new EmojiconsPopup(popupView, getApplicationContext());
// final PopupWindow popupWindow = new PopupWindow();
popupWindow.setSizeForSoftKeyboard();
popupWindow.setSize(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(mInputView.getRootView(), Gravity.BOTTOM, 0, 0);
// Bring soft keyboard up : NOT WORKING
final InputMethodManager mInputMethodManager = (InputMethodManager) getBaseContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.showSoftInput(popupView, 0);
// If the text keyboard closes, also dismiss the emoji popup
popupWindow.setOnSoftKeyboardOpenCloseListener(new OnSoftKeyboardOpenCloseListener() {
@Override
public void onKeyboardOpen(int keyBoardHeight) {
}
@Override
public void onKeyboardClose() {
if (popupWindow.isShowing())
popupWindow.dismiss();
}
});
popupWindow.setOnEmojiconClickedListener(new OnEmojiconClickedListener() {
@Override
public void onEmojiconClicked(Emojicon emojicon) {
mComposing.append(emojicon.getEmoji());
commitTyped(getCurrentInputConnection());
customToast("" + emojicon.getEmoji());
}
});
popupWindow.setOnEmojiconBackspaceClickedListener(new OnEmojiconBackspaceClickedListener() {
@Override
public void onEmojiconBackspaceClicked(View v) {
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
customToast(" " + event);
handleBackspace();
}
});
我想使用 EmojiView 在键盘顶部添加一个带有 EmojiView 的视图。现在我想要功能,就像当我为 EmojiView 键入任何主要代码时一样。我想在软键盘上显示一个 EmojiView。意思是从自己的视图中添加 pick 作为键盘的子视图。
我该怎么做?
感谢提前。请分享您的代码..
您可以使用 PopupWindow,它显示在软键盘的顶部。
看看https://github.com/ankushsachdeva/emojicon
在您的项目中添加库并使用以下代码:
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
popupWindow = new EmojiconsPopup(popupView, getApplicationContext());
// final PopupWindow popupWindow = new PopupWindow();
popupWindow.setSizeForSoftKeyboard();
popupWindow.setSize(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(mInputView.getRootView(), Gravity.BOTTOM, 0, 0);
// Bring soft keyboard up : NOT WORKING
final InputMethodManager mInputMethodManager = (InputMethodManager) getBaseContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.showSoftInput(popupView, 0);
// If the text keyboard closes, also dismiss the emoji popup
popupWindow.setOnSoftKeyboardOpenCloseListener(new OnSoftKeyboardOpenCloseListener() {
@Override
public void onKeyboardOpen(int keyBoardHeight) {
}
@Override
public void onKeyboardClose() {
if (popupWindow.isShowing())
popupWindow.dismiss();
}
});
popupWindow.setOnEmojiconClickedListener(new OnEmojiconClickedListener() {
@Override
public void onEmojiconClicked(Emojicon emojicon) {
mComposing.append(emojicon.getEmoji());
commitTyped(getCurrentInputConnection());
customToast("" + emojicon.getEmoji());
}
});
popupWindow.setOnEmojiconBackspaceClickedListener(new OnEmojiconBackspaceClickedListener() {
@Override
public void onEmojiconBackspaceClicked(View v) {
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
customToast(" " + event);
handleBackspace();
}
});