Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
¿Es posible acceder a una función de extensión escrita para TextView con enlace de datos en diseño XML?

mi función de extensión para TextView:

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

mi archivo xml con enlace de datos:

 <layout> <data> <!--some data--> </data> <LinearLayout> <TextView android:setColorifiedText="some text to be colorified" /> </LinearLayout> </layout>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sí, es posible acceder a una función de extensión escrita para una vista en XML.

Tenemos el prefijo del nombre de la función de extensión con 'set' y lo anotamos con la anotación 'BindingAdapter', por ejemplo: si el nombre de su función de extensión es 'colorText', cámbielo a 'setColorText' y acceda al mismo en XML con el nombre del atributo 'colorText' del espacio de nombres 'app:'. Además, anote la función de extensión con @BindingAdapter("colorText")

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

en xml:

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

también puede modificar el código usando el setter getter de kotlin para aprovechar

En el caso de Java, declare la función como estática y agregue un argumento al método que obtenga una referencia a la vista de texto a la que le dio el atributo.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!