-3

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.

Rajesh Panchal
  • 1,042
  • 3
  • 18
  • 38
  • take a look at this link. https://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard and if you want to disable your keyboard for whole application add this code in your application class and then extend that class to your other activities and i believe it will work. – Umair Dec 29 '17 at 10:05
  • 4
    then what does it mean to use EditText?? you can simply use TextView. – Dhruv Dec 29 '17 at 10:09
  • Best is Use `TextView` – ND1010_ Dec 29 '17 at 10:24
  • I guess some stupid people are here who are not reading the question properly and just down voting it, they should go and study well. In case if you're reading the question then let me know what's wrong with question, don't just down vote it, If you know try to help the people if you don't know then just stay away from SO and let the other people learn. – Rajesh Panchal Jan 01 '18 at 07:07

4 Answers4

2

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

0

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);
}
OmiK
  • 2,606
  • 1
  • 19
  • 35
0

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.

ND1010_
  • 2,848
  • 16
  • 33
  • how can you hide keyboard in whole application with this ? – Umair Dec 29 '17 at 10:12
  • 1
    @Umair using stateAlwaysHidden he can achieve this but after clicking on EditText keboard will viewed that's why i have also put `android:focusable="false"` – ND1010_ Dec 29 '17 at 10:15
  • yes but isn't it the bad approach that I have to give stateAlwaysHidden explicitly to all activities and also when I want to show keyboard then what will happen :). – Umair Dec 29 '17 at 10:17
  • 1
    @Umair read the question first it says **keyboard must not be appeared at any stage of my app.** – Vishva Dave Dec 29 '17 at 10:20
0

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.

Fenil Patel
  • 1,244
  • 8
  • 21