Android:如何在Softkeyboard for Emoji上添加子视图?

时间:2015-09-15 09:56:46

标签: android keyboard emoji

我想使用EmojiView在键盘顶部添加一个带EmojiView的视图。现在我想要像EimojiView那样的onkey像主代码一样的功能。我想在Softkeyboard上显示一个EmojiView。从自己的视图添加选择作为键盘子视图的方法。

我该怎么做?

谢谢你提前。请分享您的代码..

2 个答案:

答案 0 :(得分:1)

您可以使用PopupWindow,它显示在软键盘上 看https://github.com/ankushsachdeva/emojicon

答案 1 :(得分:1)

在项目中添加库并使用以下代码:

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();
    }
});