简体   繁体   English

ANDROID:软键盘无法正常工作

[英]ANDROID: Soft keyboard doesn't work properly

I had a problem with my layout, when the softkeyboard was visible, page scroll did not working.I searched through net and I find out using 我的布局出现问题,当软键盘可见时,页面滚动不起作用。我通过net搜索,发现使用

android:windowSoftInputMode="adjustResize"

solves the problem, and it did. 解决了问题,并且做到了。 However it caused some other problems. 但是,这引起了其他一些问题。 Now when I choose an edittext to type, the soft input covers the edittext and I can't see what I'm typing. 现在,当我选择要输入的编辑文本时,软输入将覆盖该编辑文本,而我看不到正在输入的内容。

So I decided to get ride of that and I removed it from my manifest. 因此,我决定搭乘该车,并将其从清单中删除。 But it didn't come back to previous state. 但是它并没有回到以前的状态。 It still works like the way it worked with adjustResize. 它仍然像使用AdjustResize一样工作。 (I cleaned and build project several times, I restarted my pc and cellphone couple times, I test it in other cellphones,...). (我多次清理并构建了项目,几次重启了PC和手机,在其他手机中进行了测试,...)。 Also, when Soft keyboard is open, and I touch to open the navigation drawer menu, the menu opens under keyboard too!!! 另外,当软键盘打开时,当我触摸以打开导航抽屉菜单时,该菜单也会在键盘下打开!!!

I can't figure out what did happened! 我不知道发生了什么事!

You can programatically remove keyboard from screen by toggling it off. 您可以通过关闭键盘来从屏幕上删除键盘。 Please try below and call it after you are done with your edittext. 完成编辑文本后,请尝试以下操作并调用它。 It will remove keyboard from screen. 它将从屏幕上删除键盘。

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

As you stated, that is for closing soft keyboard, also for handling your issue, you need to have a scroll layout as your parent layout, with using 如您所说,这是为了关闭软键盘,也为了处理问题,您需要使用滚动布局作为父布局,并使用

 android:windowSoftInputMode="adjustResize"

like you already did. 就像你已经做过的一样。 After applying those, you will have no issue. 应用这些之后,您将没有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM