AndroidDev
AndroidDev

Reputation: 2647

Android Textview content size

Is it possible to have a TextView object containing text of two sizes?


We can change the color of text content using single TextView object using textViewObj.setText(Html.fromHtml()); method. But is it possible to have text of two sizes in the single TextView object like below

like this.

What I am getting is shown below. I have tried a lot but the text is of same size.

like this

Upvotes: 2

Views: 2732

Answers (3)

Zappescu
Zappescu

Reputation: 1439

As I know, for a TextView you can just change the whole textsize using the setsize() method. Anyway, I would suggest you another approach: use two Textsize in a linearlayout, one after the other, in horizontal mode. In this manner you could change colors/size/etc for each TextView.

Edit: another approach, since you're using an html mode, is the following (maybe change with your html styles):

myTextView.setText(Html.fromHtml("<b>" + mNumbers + "</b>" +  "<small>" + mSpeed + "</small>" ));

Upvotes: 0

Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

I have checked with Editext.Then i came to know that Html.fromHtml() does not support <font> tag.I use this code

EditText text = (EditText) findViewById(R.id.title);
 text.setText(Html
            .fromHtml("<html><h3>hello</h3><h1>hello</h1>"
                    + "<p><font size=\"5\">Font</font><font 
                                        size=\"10\">size</font>"
                    + "</p></html>"));

It show different size text hello and hello but in two different line.But <font> tag value does not change any thing

enter image description here

Upvotes: 2

207
207

Reputation: 3804

You ca use Spannable:

Spannable span = new SpannableString("bigsmall");
span.setSpan(new RelativeSizeSpan(3f), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(span);

The same you can do woth color

span.setSpan(new ForegroundColorSpan(Color.GRAY), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Upvotes: 3

Related Questions