问题
I want to add a view with EmojiView on top of keyboard using EmojiView. Now I want functionality like when I onkey like primary code anything for EmojiView. I want to display a EmojiView on top of Softkeyboard. Means like adding pick from own view as subview of keyboard.
How can I do this?
Thanks for advance. Please share your code..
回答1:
You can use PopupWindow, it shows on top of Softkeyboard.
Look at https://github.com/ankushsachdeva/emojicon
回答2:
Add library in your project and use following code:
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();
}
});
来源:https://stackoverflow.com/questions/32583044/android-how-to-add-child-view-on-top-of-softkeyboard-for-emoji