How to Disable Edittext in Android

How to disable EditText in Android

I think its a bug in android..It can be fixed by adding this patch :)

Check these links
question 1
and
question 2

Hope it will be useful.

Disabling of EditText in Android

I believe the correct would be to set android:editable="false".

And if you wonder why my link point to the attributes of TextView, you the answer is because EditText inherits from TextView:

EditText is a thin veneer over
TextView that configures itself to be
editable.

Update:

As mentioned in the comments below, editable is deprecated (since API level 3). You should instead be using inputType (with the value none).

Enable/Disable editText with a Switch in Android Studio

You can set the OnCheckedChangeListener of the switch.

switchGaranzia.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//enable
} else {
//disable
}
}
});

Unable to disable EditText programmatically in kotlin android

You should use isEnabled.

Set the enabled state of this view.

 panEditText.isEnabled =false

Method Overview

@android.view.RemotableViewMethod
@Override
public void setEnabled(boolean enabled) {
if (enabled == isEnabled()) {
return;
}

if (!enabled) {
// Hide the soft input if the currently active TextView is disabled
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null && imm.isActive(this)) {
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
}

super.setEnabled(enabled);

if (enabled) {
// Make sure IME is updated with current editor info.
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) imm.restartInput(this);
}

// Will change text color
if (mEditor != null) {
mEditor.invalidateTextDisplayList();
mEditor.prepareCursorControllers();

// start or stop the cursor blinking as appropriate
mEditor.makeBlink();
}
}

EditText: how to enable/disable input?

I finally found a solution. It's a matter of calling

  • setFocusableInTouchMode(boolean)
  • setFocusable(boolean)

when the EditText is first created, so it can intercept the clicks. Then one can set those flags back again to make the EditText editable, request the focus, and manually show/hide the soft keyboard with InputMethodManager methods



Related Topics



Leave a reply



Submit