How do I use databinding to combine a string from resources with a dynamic variable in XML?

前端 未结 9 961
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 13:30

I have a TextView which has a hardcoded string and I have a dynamic variable that I want to put at the end of this string. This is my code:



        
9条回答
  •  忘掉有多难
    2020-12-07 13:55

    In case if you want to type text in XML, you can use `` quotation.

    android:text="@{`Device Name`}"
    

    elsewhere you need to Concat with the String or variable, you can use

    android:text="@{`Device Name`.concat(android.os.Build.MANUFACTURER)}"
    

    if you want to Concat string resource instead of the variable you can do,

    android:text="@{@string/app_name.concat(`Device Name`)}"
    

提交回复
热议问题