8

我有一个 TableLayout,我在 OnCreate 的代码中动态添加内容。一旦 Activity 创建,它就会专注于我动态创建的 EditText 之一并显示键盘。在用户专门按下 EditText 之一之前,我不希望键盘显示。我试过了:

InputMethodManager input = (InputMethodManager) GetSystemService(InputMethodService);
input.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);

但是键盘仍然显示并且 CurrentFocus 返回 null。因此,当我尝试将焦点专门指向另一个视图然后执行上述操作时:

InputMethodManager input = (InputMethodManager) GetSystemService(InputMethodService);
title.FindFocus();
input.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);

CurrentFocus 仍然为空,键盘仍然显示。title 是一个 TextView,我已经在代码中有一个实例。我可以不把焦点放在 TextView 上还是我还缺少其他东西?

4

3 回答 3

28
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
于 2012-04-20T13:06:04.640 回答
10

好简单

  1. 转到您的AndroidManifest.xml文件
  2. 在您的活动中添加:android:windowSoftInputMode="stateHidden"

例如:

<activity
         android:name=".package.example.MyActivity"
            android:windowSoftInputMode="stateHidden"/>
于 2016-02-08T22:37:52.640 回答
1
  1. 转到 AndroiManifest.xml 文件
  2. 要隐藏键盘的活动添加以下内容

    android:windowSoftInputMode="stateHidden|adjustResize|stateAlwaysHidden"

于 2018-10-19T06:41:08.843 回答