我正在我的应用程序中聊天,我有一个表情 fragment (就像来自 whatsapp 或电报的 fragment )。如何在没有任何奇怪动画的情况下在 fragment 和键盘之间切换?
我已经有了带有表情符号和自定义 EditText 的 fragment 。我只想在那个 fragment 和键盘之间切换。我真的希望它像 whatsapp 或 Telegram 一样工作。
对于表情 fragment 我做了一个库。我在与 EditText 相同的布局中添加了一个 fragment (每个表情符号都带有 SpannableTextViews 的 GridView )。
任何帮助将不胜感激。
最佳答案
您不需要更换键盘,您可以使用 PopupWindow 将您的 fragment 放在 Activity 上正如 Telegram
所做的那样。看看source : 方法 showEmojiPopup
创建 EmojiView
并将其放入 PopupWindow
然后计算适当的大小并显示它。
emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY));
emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(contentView.getWidth(), View.MeasureSpec.EXACTLY));
emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), 83, 0, 0);
关于Android 用 Emoji Fragment 替换键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23596004/