Edit Text入力のあるアクティビティがあります。アクティビティが初期化されると、Androidキーボードが表示されます。ユーザーが入力にフォーカスするまで、キーボードを非表示にしておくにはどうすればよいですか?
android:windowSoftInputMode="adjustPan"?
                Edit Text入力のあるアクティビティがあります。アクティビティが初期化されると、Androidキーボードが表示されます。ユーザーが入力にフォーカスするまで、キーボードを非表示にしておくにはどうすればよいですか?
android:windowSoftInputMode="adjustPan"?
                回答:
以下がうまくいくと思います
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
私は以前、この種のものに使用したことがあります。
EditTextますか?:)これは、アクティビティの開始時にキーボードを非表示にするためのものですEditText
                    これも試してください-
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
それ以外の場合は、マニフェストファイルのアクティビティで宣言します-
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
          android:label="@string/app_name"
          android:windowSoftInputMode="stateHidden"
          >
またはのandroid:windowSoftInputModeような値をすでに使用している場合は、次のような2つの値を組み合わせることができます。adjustResizeadjustPan
<activity
        ...
        android:windowSoftInputMode="stateHidden|adjustPan"
        ...
        >
これにより、キーボードは適切に非表示になりますが、キーボードを表示する必要がある場合は、アクティビティビューをパンします。
テーマを使用するすべてのアクティビティで非表示にします
<style name="MyTheme" parent="Theme">
    <item name="android:windowSoftInputMode">stateHidden</item>
</style>
テーマを設定する
<application android:theme="@style/MyTheme">
              これら2つのプロパティを親レイアウトに追加します(例:線形レイアウト、相対レイアウト)
android:focusable="false"
android:focusableInTouchMode="false" 
それはトリックを行います:)
trueジャックTの回答に従って、それらを機能するように設定します。最近のバージョンで動作の変更はありましたか?
                    falseただし、これらの設定が機能する理由はわかりません。これは、EditTextボックスからフォーカスを外すことを目的としているためです。
                    目録ファイルでそれを宣言してみてください
<activity android:name=".HomeActivity"
      android:label="@string/app_name"
      android:windowSoftInputMode="stateAlwaysHidden"
      >
              また、「問題」がある.xmlレイアウトファイルの直接の親レイアウトに次のコード行を書き込むこともできます。
android:focusable="true"
android:focusableInTouchMode="true"
例えば:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    ...
    android:focusable="true"
    android:focusableInTouchMode="true" >
    <EditText
        android:id="@+id/myEditText"
        ...
        android:hint="@string/write_here" />
    <Button
        android:id="@+id/button_ok"
        ...
        android:text="@string/ok" />
</LinearLayout>
編集:
EditTextが別のレイアウトに含まれている場合の例:
<?xml version="1.0" encoding="utf-8"?>
<ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    ... >                                            <!--not here-->
    ...    <!--other elements-->
    <LinearLayout
        android:id="@+id/theDirectParent"
        ...
        android:focusable="true"
        android:focusableInTouchMode="true" >        <!--here-->
        <EditText
            android:id="@+id/myEditText"
            ...
            android:hint="@string/write_here" />
        <Button
            android:id="@+id/button_ok"
            ...
            android:text="@string/ok" />
    </LinearLayout>
</ConstraintLayout>
重要なのは、EditTextが直接フォーカス可能でないことを確認することです。
バイバイ!;-)
私にとって最良の解決策、あなたのクラスを貼り付けてください
@Override
public void onResume() {
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    super.onResume();
}
@Override
public void onStart() {
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    super.onStart();
}
              キーボードを非表示にする機能。
public static void hideKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
AndroidManifext.xmlファイルでキーボードを非表示にします。
<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:windowSoftInputMode="stateHidden">
              @Lucasが受け入れた回答を拡張するには:
初期のライフサイクルイベントの1つでのアクティビティからこれを呼び出します。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
override fun onResume() {
  super.onResume()
  window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
}
              各要素に対してこの設定された一意の属性を試すことができます
TextView mtextView = findViewById(R.id.myTextView);
mtextView.setShowSoftInputOnFocus(false);
要素にフォーカスがある間、キーボードは表示されません
これをアクティビティに追加するだけです:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
      if (getCurrentFocus() != null) {
           InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
           imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
      }
      return super.dispatchTouchEvent(ev);
}
              
<activity android:windowSoftInputMode="stateHidden" ...>