Thank you very much for the response. It almost worked.
Please check the following code if I implemented your method as you
intended:
public Spanned setSpeedText(){
StringBuilder hTmlSB = new StringBuilder()
.append("<font size=\"8\">")
.append(kMph[DID])
.append("</font>")
.append("<font size=\"2\">km/h</font>");
String hTmlString = hTmlSB.toString();
systemMessage.setText(hTmlString);
Spanned st = Html.fromHtml(hTmlString);
errorMessage.setText(st);
return st;
}
I added the <font size="8"></font> part of the code when the
button.setText() and errorMessage.setText() completely ignored any
HTML font size I specified for "km/h" without these two lines.
But the result is exactly the same regardless that the button, whose
setText() called setSpeedText(), and TextView errorMessage both
showing the entire "46.6km/h" in the default font size specified in /
res/layout/main.xml as they did before applying the trick.
FYI, both systemMessage and errorMessage are normal TextView; target
is Android 2.3.3; and systemMessage shows proper HTML as <font
size="8">46.6</font><font size="2">km/h</font>.
Am I doing it right?
The reference for Html.fromHtml says "Returns displayable styled text
from the provided HTML string.", which leaves the question of
"displayable by what", other than TextView and Button.
Although "final void TextView.setText(Spanned string)" is not
documented, either; the fact that this trick did not cause any anomaly
nor create error makes the whole picture even more frustrating as I
thought and appreciated your idea as being marvelous.
On May 4, 9:45 pm, Mark Murphy <[email protected]> wrote:
>
> Try this:
>
> Step #1: Create an HTML string that uses <font size=""> tags to adjust
> the font size (e.g., "46.6 <font size="2">km/h</font>")
>
> Step #2: Convert that string into a SpannedString by use of Html.fromHtml()
>
> Step #3: Put that SpannedString as the caption of your button via setText()
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en