Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
Is it possible to access an extension function written for TextView with Databinding in XML layout?

my extension function for TextView:

fun TextView.setColorifiedText(text : String) {
 // Some logic to change color of text
 setText(text)
}

my xml file with databinding:

<layout>
   <data>
      <!--some data-->
   </data>
   <LinearLayout>
      <TextView 
        android:setColorifiedText="some text to be colorified"
      />
   </LinearLayout>
</layout>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Yes, it is possible to access an extension function written for a view in XML.

We have prefix the extension function name with 'set' and annotate it with 'BindingAdapter' annotation., for ex:- if your extension function name is 'colorText' change it to 'setColorText' and access the same in XML with the attribute name 'colorText' from 'app:' namespace. Also, annotate the extension function with @BindingAdapter("colorText")

@BindingAdapter("colorText")
fun TextView.setColorText(text : String) {
   // logic to something with the text
}

in XML :

<TextView
   app:colorText="your String" />

you can also modify the code using the kotlin's setter getter to advantage

In case of java declare the function as static and add an argument to the method which gets reference to the textview you gave the attribute to.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda