How to prevent the soft keyboard from popping up while using a physical keyboard in Android app? kotlin or java

Viewed 24

I want to prevent the soft keyboard from popping up while using a physical keyboard in Android app.

I have tried inputmanager

val inputMethodManager: InputMethodManager = context?.getSystemService(
                    AppCompatActivity.INPUT_METHOD_SERVICE
                ) as InputMethodManager
                inputMethodManager.showInputMethodPicker()

and also used this

editText.showSoftInputOnFocus = false

but the soft keyboard still popups when I start typing on the physical keyboard.

1 Answers

Try This

MainActivity.java

This Code Hide Soft Keyboard in your Project

  public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    }
  }
Related