Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to disable EditText programmatically in kotlin android

Tags:

android

kotlin

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?

like image 611
sagar suri Avatar asked Mar 31 '18 18:03

sagar suri


People also ask

How to make EditText not Editable in Android programmatically?

In your xml code set focusable="false" , android:clickable="false" and android:cursorVisible="false" and this will make your EditText treat like non editable.


Video Answer


1 Answers

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();
        }
    }
like image 74
IntelliJ Amiya Avatar answered Oct 10 '22 02:10

IntelliJ Amiya