Combining Spannable with String.format()

前端 未结 5 475
刺人心
刺人心 2021-01-31 09:28

Suppose you have the following string:

String s = \"The cold hand reaches for the %1$s %2$s Ellesse\'s\";
String old = \"old\"; 
String tan = \"tan\"; 
String fo         


        
5条回答
  •  长发绾君心
    2021-01-31 09:45

    I had the same issue pop up, but found a really great solution here: Android: How to combine Spannable.setSpan with String.format?

    Check out the solution offered by @george-steel. He created a custom version of String.format which preserves spans.

    Example use:

    Spanned toDisplay = SpanFormatter.format(getText(R.string.foo), bar, baz, quux);
    

提交回复
热议问题