【发布时间】:2016-10-15 13:32:11
【问题描述】:
我不知道如何在 android 按钮中设置上标文本(用于数学运算符)。
正如下面的代码所示,我希望 buttonXPow 显示:
Xy
我希望 button10Pow 显示:
10年
我想避免在可能的情况下显示X^y 和10^y。
到目前为止,我发现的唯一可能的解决方案是这段代码 (found in this stackoverflow question here):
protected void onCreateView() {
if (rootView.findViewId(R.id.buttonXPow) !=null) {
((Button) rootView.findViewById(R.id.buttonXPow)).setText(Html.fromHtml("X <sup><small> y </small></sup>"));
}
if (rootView.findViewId(R.id.button10Pow) !=null) {
((Button) rootView.findViewById(R.id.button10Pow)).setText(Html.fromHtml("10 <sup><small> y </small></sup>"));
}
}
这个问题是rootView 无法解决。我不确定我如何才能让它工作(显然它不是我需要导入的类;我假设我需要以某种方式声明一个变量)。
还有其他已知的设置上标文本的方法吗?也许使用 xml 而不是在主 java 类中?
【问题讨论】:
-
检查这个:stackoverflow.com/questions/3543454/… 它有在 xml 文件中声明文本的答案
-
可以,非常感谢
标签: android android-studio button superscript