Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw view on top of soft keyboard like WhatsApp?

I want to know how it's possible to add View on top of Keyboard like WhatsApp and Hangout. In chat screen, they insert emoticons view on top of the opened soft keyboard.

sample image

Does anyone know how to achieve this behavior?

like image 379
and_dev Avatar asked Apr 17 '13 12:04

and_dev


1 Answers

Well, I have created a sample keyboard for chatting here...

Here, I use popup window for showing popup window and height of popup is calculated dynamically by height of keyboard

// Initially defining default height of keyboard which is equal to 230 dip         final float popUpheight = getResources().getDimension(                 R.dimen.keyboard_height);         changeKeyboardHeight((int) popUpheight);  // Creating a pop window for emoticons keyboard     popupWindow = new PopupWindow(popUpView, LayoutParams.MATCH_PARENT,             (int) keyboardHeight, false); 

and height is calculated using this function :

/**  * Checking keyboard height and keyboard visibility  */ int previousHeightDiffrence = 0; private void checkKeyboardHeight(final View parentLayout) {      parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(             new ViewTreeObserver.OnGlobalLayoutListener() {                  @Override                 public void onGlobalLayout() {                      Rect r = new Rect();                     parentLayout.getWindowVisibleDisplayFrame(r);                      int screenHeight = parentLayout.getRootView()                             .getHeight();                     int heightDifference = screenHeight - (r.bottom);                      if (previousHeightDiffrence - heightDifference > 50) {                                                   popupWindow.dismiss();                     }                      previousHeightDiffrence = heightDifference;                     if (heightDifference > 100) {                          isKeyBoardVisible = true;                         changeKeyboardHeight(heightDifference);                      } else {                          isKeyBoardVisible = false;                      }                  }             });  } 

Using all these stuff i am able to make a perfect overlapping keyboard....

then i inflate popup window with viewpager and gridview for emoticons.

Also, i use spannable string for showing these emoticons in listview and chat window

like image 140
Chirag Jain Avatar answered Sep 30 '22 02:09

Chirag Jain