在我的活动课中,我使用自定义键盘和android软文字键盘。 Android文本软键盘调整活动布局。如果我在打开软键盘时打开自定义键盘,则最后一个隐藏,布局会向后展开。但我打电话后立即打开自定义键盘
InputMethodManager imm = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(view.WindowToken, 0);
此处视图是使用自定义键盘的视图。 当自定义键盘绘制两次时,我遇到了问题:
我想做的是以某种方式避免两个键盘同时出现。 在活动代码中,我只使用SoftInput.StateAlwaysHidden WindowSoftInputMode。 SoftInput.AdjustPan不方便,因为在这种情况下,某些视图可以被Android键盘隐藏。
答案 0 :(得分:1)
经过数小时的互联网搜索后,找到了答案。 Pspdfkit有great post。
通过小规模调查,它已在Oncreate方法中用C#重写:
private View decorView;
private int lastVisibleDecorViewHeight = 0;
decorView = Window.DecorView;
decorView.ViewTreeObserver.GlobalLayout += (sender, args) =>
{
Rect windowVisibleDisplayFrame = new Rect();
decorView.GetWindowVisibleDisplayFrame(windowVisibleDisplayFrame);
int visibleDecorViewHeight = windowVisibleDisplayFrame.Height();
if (lastVisibleDecorViewHeight != 0)
{
if (lastVisibleDecorViewHeight > visibleDecorViewHeight)
{
OnSoftKeyboardShown();
}
else if (lastVisibleDecorViewHeight < visibleDecorViewHeight)
{
OnSoftKeyboardHidden();
if (!isAndroidSoftKeyboardShown && customKeyboardRequested)
{
Keyboard.RequestCustomKeyboard(requestedCustomKeyboardType);
customKeyboardRequested = false;
}
}
}
lastVisibleDecorViewHeight = visibleDecorViewHeight;
};
希望这能帮助有类似问题的人。