irfan
irfan

Reputation: 869

how to disable softkeyboard in an activity?

I want to disable keyboard pop up in my activity. There will not be any keboard in the actvity. but hardware keyboard must work.how to do this? hardware buttons must work

Upvotes: 0

Views: 133

Answers (3)

Srijith
Srijith

Reputation: 1715

Use this in your manifest:

<activity android:name=".SampleActivity" android:windowSoftInputMode="stateAlwaysHidden"/>

Upvotes: 1

Dhruv
Dhruv

Reputation: 1872

Just try below code.

InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editView.getWindowToken(), 0);

Upvotes: 1

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

Managing soft keyboard in android is not that easy, although you can hide keyboard programatically.

private void hideKeyboard() {   
    //This will get any view in focus.
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

note that Hardware Keyboard will work.

Upvotes: 0

Related Questions