如何在 WhatsApp 等软键盘上绘制视图? [英] How to draw view on top of soft keyboard like WhatsApp?
问题描述
我想知道如何将 View
添加到键盘之上,例如 WhatsApp 和 Hangout.在聊天屏幕中,他们在打开的软键盘顶部插入表情视图.
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.
有谁知道如何实现这种行为?
Does anyone know how to achieve this behavior?
推荐答案
好吧,我已经创建了一个示例键盘用于在 此处一个>...
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....
然后我使用 viewpager 和 gridview 为表情符号充气弹出窗口.
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
这篇关于如何在 WhatsApp 等软键盘上绘制视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!