Kiran Malvi Kiran Malvi - 3 months ago 44
Android Question

Formatting multiple string into one string

So my requirement is as follows:
I've multiple strings stored in different string variables, lot of them are hardcore string, some of them are user inputs, while some are values from database(online as well as offline database.)
I want to combine all the strings in single String variable but I want each letter formatted differently as shown in following image.

Formatted String should look something like this

where as my normal string would be like this:

MAIN TITLE SUBTITLE: Detail 1 Detail 2 Heading 1: User Input Data Heading 2: User Input Data.

Thank you!


Spannable String is your solution.

Refer this

Also refer this

Here is an example:

final SpannableString text = new SpannableString("Hello World");
text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "World".length(),text.length(),
text.setSpan(new ForegroundColorSpan(Color.BLACK), 4, text.length() - 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);