Rediska
Rediska

Reputation: 1470

How to prevent soft keyboard from appearing on touch

I don't want the soft keyboard to appear when a particular EditText is touched. But I still want to be able to show the soft keyboard upon user request (say, when a button is pressed) and allow the user to edit the text. I know how to show/hide the soft keyboard, I only don't know how to prevent it from appearing on touch. Any suggestion how to do it?

The general idea is that the user will be mostly working with selection/position within the text, and only occasionaly entering characters. I don't want the visible amount of text to be reduced by the soft keyboard when selecting or navigating the text.

Upvotes: 3

Views: 1243

Answers (6)

Ashwani Kumar
Ashwani Kumar

Reputation: 1472

Why don't you disable the edittext. Then it will not show keyboard on click. To this you can:

android:editable="false" //from xml
et.setEnabled(false);  //from activity

And then on your buttonClick make it enable by setting above code true. And make your keyboard appear.

Also If you don't get the focus on edittext you can:

et.requestFocus(); // from activity

<EditText
    android:id="@+id/et1"
    android:editable="false"
    android:layout_width="150dp"
    android:layout_height="wrap_content" >
    <requestFocus/>
</EditText> 

//from xml

Hope this helps!

Upvotes: 0

bryan c
bryan c

Reputation: 1366

simply use

 txtEdit.setShowSoftInputOnFocus(false);

and when you want to enable that , reverse above process

Upvotes: 3

Rediska
Rediska

Reputation: 1470

This works:

editText.setShowSoftInputOnFocus(false);

Upvotes: 1

raasesh
raasesh

Reputation: 161

Try the below code, it hides the keyboard:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)

Upvotes: 0

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

AndroidManifest.xml windowSoftInputMode

 <activity android:name=".MyActivity" android:windowSoftInputMode="adjustPan"> </activity>

Upvotes: 0

raasesh
raasesh

Reputation: 161

within the activity in the manifest add the below code
android:windowSoftInputMode="adjustPan"

Upvotes: 0

Related Questions