Material-components-android: [TextInputLayout] OnFocusChangeListener is only notified on first gained focus

Created on 12 Feb 2020  路  6Comments  路  Source: material-components/material-components-android

Description:
Settings a OnFocusChangeListener on the TextInputEditText inside the TextInputLayout notifies the listener only the very first time the focus is gained.

Expected behavior:
The listener should always fire when focus is gained and lost.

Source code:

textInputEditText.setOnFocusChangeListener { _, hasFocus -> 
  println("only fires on first focus gained")
}

Android API version: 29

Material Library version: 1.2.0-alpha04

Device: Emulator

bug

Most helpful comment

I have the exact same issue, as described by kazougagh. When setting endIconMode programatically its never called again.

All 6 comments

Hi, I'm not able to reproduce the issue. Could you provide a sample app?

Ok, closing this issue.

Hi,
I have the same issue here. Why this ticket has been closed ? Is there a fix available ?
Thanks

@kazougagh can you provide a sample app with the issue since it's not reproducible on our end?

Hi @leticiarossi ,
This issue occurs when you try to set the endIconMode programmatically and not using the xml attributes. Like this:

`

 val inputLayout = findViewById<TextInputLayout>(R.id.text_input_layout)
 inputLayout.editText?.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->

        // ----------------------------
        // Called on first focus only !
        // ----------------------------

        Log.d(TAG, "inputEditText - hasFocus $hasFocus")
        if (inputLayout.endIconMode == TextInputLayout.END_ICON_NONE) {
            inputLayout.endIconMode = TextInputLayout.END_ICON_CLEAR_TEXT
            inputLayout.setEndIconTintList(ColorStateList.valueOf(getColor(R.color.colorPrimaryDark)))
        }

    }`

I have the exact same issue, as described by kazougagh. When setting endIconMode programatically its never called again.

Was this page helpful?
0 / 5 - 0 ratings