开发者

Format and style a xml resource + assign to textview

开发者 https://www.devze.com 2023-03-29 23:30 出处:网络
I\'d like to format a string from resource and do some formatting on it, too! xml resource: <string name=\"itemFormatString\">%1$s\\n\\n<i>%2$s</i></string>

I'd like to format a string from resource and do some formatting on it, too!

xml resource:

<string name="itemFormatString">%1$s\n\n<i>%2$s</i></string>

I've tried several combination but i didnt get it how to solve that directly. I do not want to create any Spannable objects within code, which should not be neccessary imo. (I made it working already using a Spannable, because i dont get how to both format a resource s开发者_Python百科tring but still keep the "style" character).

The ending up string gets assigned to a textview.

greetings, michael


Just add whatever styles you want to the TextView in your xml. For instance, if you wanted to make your String bold (as an easy example) just do:

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold" />

And then in your activity just set your string to the formatted textView:

findViewById(R.id.textView).setText(itemFormatString);
0

精彩评论

暂无评论...
验证码 换一张
取 消