I am trying to disable an EditText
programmatically in Kotlin
but I am not finding any method to do. I tried below code which didnt work:
panEditText.focusable = false //Requires API 26 and above.
panEditText.enabled = false //No such method found
How to disable EditText
in Kotlin
programming language?
In your xml code set focusable="false" , android:clickable="false" and android:cursorVisible="false" and this will make your EditText treat like non editable.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With