Reputation: 3381
I am working on a dialog at Android with a few EditText
s.
I've put this line at the onCreate()
in order to disable the soft keyboard:
Keypad.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
The problem is that it works only when the dialog appear and doing nothing.
When I move to the next EditText
, the keyboard appears and not going down.
Does anybody have an idea how to solve this issue?
Upvotes: 24
Views: 43037
Reputation: 5630
Call TextView.setShowSoftInputOnFocus(false)
. This method is documented since API level 21, but it's already there since API level 16 (it's just hidden from JavaDoc). I use it with API level 16 in an AlertDialog in combination with dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
.
In API level 14, there is a hidden method setSoftInputShownOnFocus()
which seems to have the same purpose, but I have not tested that.
The advantage over InputType.TYPE_NULL
is, that all the normal input types can be used (e.g. for password input) and the touch event positions the cursor at the correct spot within the text.
Upvotes: 5
Reputation: 7350
create your own class that extends EditText
and override the onCheckIsTextEditor()
:
public class NoImeEditText extends EditText {
public NoImeEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onCheckIsTextEditor() {
return false;
}
}
Upvotes: 27
Reputation: 364
Know its too late, but have you tried the following setting to EditText in your layout ?
android:inputType="none"
UPDATE
Use,
editText.setInputType(InputType.TYPE_NULL)
editText.setFocusable(false)
Upvotes: 2
Reputation: 355
You can do that:
textView.setOnClickListener(null);
It will disable the keyboard to the textView and the click will not work anymore.
Upvotes: 0
Reputation: 13031
by set EditText focusable->false, keyboard will not opened when clicked
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
Upvotes: 0
Reputation: 3069
If you put the textViews in the view group you can make make the view get the focus before any of its descendants by using this:
view.setDescendantFocusability(view.FOCUS_BLOCK_DESCENDANTS);
Upvotes: 0
Reputation: 3705
Try this out..
edittext.setInputType(InputType.TYPE_NULL);
if (android.os.Build.VERSION.SDK_INT >= 11)
{
edittext.setRawInputType(InputType.TYPE_CLASS_TEXT);
edittext.setTextIsSelectable(true);
}
Upvotes: 22
Reputation: 1417
Put this in Oncreate Method
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Upvotes: 3
Reputation: 1010
in order to disable ANDROID SOFT INPUT KEYBOARD xml file doesn't help in my case calling the setInputType method on EditText object in java file works great. here is the code.
EditTextInputObj = (EditText) findViewById(R.id.EditTextInput);
EditTextInputObj.setInputType(InputType.TYPE_NULL);
Upvotes: 0
Reputation: 982
I have been looking for solutions to this all day, and I came across this approach. I'm putting it here because it seems to answer this question perfectly.
EditText et = ... // your EditText
et.setKeyListener(null) //makes the EditText non-editable so, it acts like a TextView.
No need to subclass. The main difference between this and making your EditText non-focusable, is that the EditText still has its own cursor - you can select text, etc. All it does is suppress the IME from popping up its own soft keyboard.
Upvotes: 5
Reputation: 5278
Its been some time since this post, but here is a simple method which worked for me: in the xml, in the EditText
properties, do: android:focusable="false"
. Now the keyboard will not popup even if the user clicks on it. This is useful if you are providing your own keypad.
Upvotes: 4
Reputation: 2694
If you take look on onCheckIsTextEditor() method implementation (in TextView), it looks like this:
@Override
public boolean onCheckIsTextEditor() {
return mInputType != EditorInfo.TYPE_NULL;
}
This means you don't have to subclass, you can just:
((EditText) findViewById(R.id.editText1)).setInputType(InputType.TYPE_NULL);
I tried setting android:inputType="none" in layout xml but it didn't work for me, so I did it programmatically.
Upvotes: 36
Reputation:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edSearch.getWindowToken(), 0);
Upvotes: 0