如何保持软键盘从Android的开放活动上推出?键盘、Android

2023-09-03 21:03:19 作者:晚間新聞

在一个Android应用程序,只要该活动启动后,文本框获得焦点和软键盘会自动弹出。我曾尝试通过使用onCreate方法以下行停止,但它不能正常工作。

 ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))hideSoftInputFromWindow(EditText.getWindowToken(),0);
 

解决方案

我知道这是旧的,但也许这将帮助别人的未来......

我还没有见过任何人提出stateHidden

android 键盘高度 如何在Android上调整Google键盘的高度

从Android文档 - 安卓windowSoftInputMode

您清单文件看起来像:

 <活动
    ...
    机器人:windowSoftInputMode =stateHidden | adjustResize
    ...
>
 

In an Android app, whenever the activity launches, the textbox gets the focus and the soft keyboard pops up automatically. I have tried to stop this by using following line in onCreate method, but it does not work.

((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(EditText.getWindowToken(), 0);

解决方案

I know this is old but maybe it will help someone in the future...

I haven't seen anyone suggest "stateHidden"

From the Android docs - android:windowSoftInputMode

Your manifest file would look like:

<activity
    ...
    android:windowSoftInputMode="stateHidden|adjustResize"
    ...
>

 
精彩推荐
图片推荐