add view over keyboard android add view over keyboard android android android

add view over keyboard android


Unfortunately, as far for Android 5.0 (dont know after) theres no way to get the keyboard height. So you can't use this value to position your View.

But, you can use the softKeyboard relayout to do what you want, by using softKeyboard (at the Activity manifest) with a value of "resize" will make your root layout View to be resized to the size of the remaining screen space. By positioning your view at the bottom will make it exactly on top of the keyboard.

PS: Also, your root view needs its height value to be match_parent instead of anything else (or you will need to deal in hard other ways)

Maybe you mean you want to replace the keyboard location instead of being on "top of it" (NORTH?), in this case, you should use a CustomView that extends View and not use the EditText that does open the keyboard for you


You will have to hide the keyboard while showing window of emoji via:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edText.getWindowToken(), 0);

where edText is the edittext you have currently focus on.

EDIT:This is my code merged into yours.you can give it a try.

    private void showEmojiPopup(boolean show) {    showingEmoji = show;    if (show) {        if (emojiView == null) {            if (getActivity() == null) {                return;            }            emojiView = new EmojiView(getActivity());            emojiView.setListener(new EmojiView.Listener() {                public void onBackspace() {                    chatEditText1.dispatchKeyEvent(new KeyEvent(0, 67));                }                public void onEmojiSelected(String symbol) {                    int i = chatEditText1.getSelectionEnd();                    if (i < 0) {                        i = 0;                    }                    try {                        CharSequence localCharSequence = Emoji.replaceEmoji(symbol, chatEditText1.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));                        chatEditText1.setText(chatEditText1.getText().insert(i, localCharSequence));                        int j = i + localCharSequence.length();                        chatEditText1.setSelection(j, j);                    } catch (Exception e) {                        Log.e(Constants.TAG, "Error showing emoji");                    }                }            });            windowLayoutParams = new WindowManager.LayoutParams();            windowLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;            Log.d(TAG ,Build.VERSION.SDK_INT + " ");            if (Build.VERSION.SDK_INT >= 21) {                windowLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;            } else {                windowLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;                windowLayoutParams.token = getActivity().getWindow().getDecorView().getWindowToken();            }            windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;            Log.d("emoj",WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + "");        }        final int currentHeight;        if (keyboardHeight <= 0)            keyboardHeight = App.getInstance().getSharedPreferences("emoji", 0).getInt("kbd_height", AndroidUtilities.dp(200));        currentHeight = keyboardHeight;        WindowManager wm = (WindowManager) App.getInstance().getSystemService(Activity.WINDOW_SERVICE);        windowLayoutParams.height = currentHeight;        windowLayoutParams.width = AndroidUtilities.displaySize.x;        try {            if (emojiView.getParent() != null) {                wm.removeViewImmediate(emojiView);            }        } catch (Exception e) {            Log.e(Constants.TAG, e.getMessage());        }        try {            wm.addView(emojiView, windowLayoutParams);        } catch (Exception e) {            Log.e(Constants.TAG, e.getMessage());            return;        }        if (!keyboardVisible) {            if (sizeNotifierRelativeLayout != null) {                sizeNotifierRelativeLayout.setPadding(0, 0, 0, currentHeight);            }            return;        }    } else {        removeEmojiWindow();        if (sizeNotifierRelativeLayout != null) {            sizeNotifierRelativeLayout.post(new Runnable() {                public void run() {                    if (sizeNotifierRelativeLayout != null) {                        sizeNotifierRelativeLayout.setPadding(0, 0, 0, 0);                    }                }            });        }    }} @Overridepublic void onSizeChanged(int height) {    Rect localRect = new Rect();    getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);    WindowManager wm = (WindowManager) App.getInstance().getSystemService(Activity.WINDOW_SERVICE);    if (wm == null || wm.getDefaultDisplay() == null) {        return;    }    if (height > AndroidUtilities.dp(50) && keyboardVisible) {        keyboardHeight = height;        App.getInstance().getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit();    }    if (showingEmoji) {//code to hide keyboardInputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);            imm.hideSoftInputFromWindow(edText.getWindowToken(), 0);//end        int newHeight = 0;        newHeight = keyboardHeight;        if (windowLayoutParams.width != AndroidUtilities.displaySize.x || windowLayoutParams.height != newHeight) {            windowLayoutParams.width = AndroidUtilities.displaySize.x;            windowLayoutParams.height = newHeight;            wm.updateViewLayout(emojiView, windowLayoutParams);            if (!keyboardVisible) {                sizeNotifierRelativeLayout.post(new Runnable() {                    @Override                    public void run() {                        if (sizeNotifierRelativeLayout != null) {                            sizeNotifierRelativeLayout.setPadding(0, 0, 0, windowLayoutParams.height);                            sizeNotifierRelativeLayout.requestLayout();                        }                    }                });            }        }    }


You can create a custom EditText and disable showing the keyboard by override onCheckIsTextEditor. Refer code below:

  public class NoKeyBoardEditText extends EditText {   @Override         public boolean onCheckIsTextEditor() {         return false;        }     }