Android:显示x的y次方

3

需要帮助!如何在Android的TextView中显示上标数字。例如,如果您想要显示一些摄氏度,可以这样做:textview.setText(number+"\u2103"),但我无法找到一种方法来显示类似于number^anothernumber的内容。

谢谢!

3个回答

7

将字符串格式化为HTML,然后使用HTML上标标签<sup>

textView = (TextView)findViewById(R.id.textView);
String text = "x<sup>y</sup>";
textView.setText(Html.fromHtml(text));

同样地,如果你想使用下标,请使用<sub>标签。

3
您可以使用简单的HTML格式:
String str = number + "<sup>" + anotherNumber + "</sup>";
textView.setText(Html.fromHtml(str), TextView.BufferType.SPANNABLE);

1
你可以使用TextView来显示HTML标记,这应该可以工作;

textView.setText(android.text.Html.fromHtml("x<sup>y</sup>"));


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接