Rajesh Panchal
Rajesh Panchal

Reputation: 1170

Disable keyboard for my app programmatically

I want to disable keyboard for my entire app, i.e keyboard must not be appeared at any stage of my app, My app contains WebView and the which I'm loading is having input fields at that point I don't want android's keyboard because that page itself contains keyboard which gets open when clicking on input field. what I know is

InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);     
inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

but with this code when I click on edittext keyboard gets open.

Upvotes: 0

Views: 8800

Answers (4)

Nagendra Hari Karthick
Nagendra Hari Karthick

Reputation: 483

add focusable: false to your xml code(EditText), it will do the job

Upvotes: 2

ND1010_
ND1010_

Reputation: 3841

In androidManifest.xml put this line in activity android:windowSoftInputMode="stateAlwaysHidden"

like this

<activity
     android:name="com.app.thumbpin.activity.HomeActivity"
     android:windowSoftInputMode="stateAlwaysHidden" />

and use in every EditText android:focusable="false" as below

<EditText
        android:id="@+id/EditTextInput"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:gravity="right"
        android:cursorVisible="true">
    </EditText>

parametrically hiding keyboard

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

In xml :

Write android:descendantFocusability="blocksDescendants" in root layout tag.

Upvotes: 3

Fenil Patel
Fenil Patel

Reputation: 1546

TRY THIS,

Create your own class that extends EditText and override the onCheckIsTextEditor()

public class CustomEditText extends EditText {
    public NoImeEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean onCheckIsTextEditor() {
        return false;
    }
}

And in the layout XML use a fully qualified reference to your custom control instead of EditText:

<com.yourpackge.path.CustomEditText
              ........
    enter code here

           .....................
/> 

It will disable focus of soft keyboard for all EditText.

Upvotes: -1

Omkar
Omkar

Reputation: 3100

disable above API 11 like below

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // API 21
    editText.setShowSoftInputOnFocus(false);
} else { // API 11-20
    editText.setTextIsSelectable(true);
}

Upvotes: 1

Related Questions