我正在使用
private final static String MICRO = "&#x3BC";
和
private final static String SQUARE = "&#xB2";
将ms ^ 2和MICRO符号显示为
case Sensor.TYPE_ACCELEROMETER:
units = "m/s" + SQUARE;
case Sensor.TYPE_MAGNETIC_FIELD:
units = MICRO + "T";
但它返回相同的值。即MICRO = "&#x3BC"; and SQUARE = "&#xB2";
在App上。有没有其他方式来显示这些单位?
答案 0 :(得分:0)
只需更改MICRO = "&#x3BC"; to MICRO = "μ";
和
SQUARE = "&#xB2"; to SQUARE = "²";
有效
答案 1 :(得分:0)
这是另一个选项 - 使用HTML。
首先,创建XML字符串
<string name="ms"><![CDATA[%1$s m/s<sup><small><small>2</small></small><sup>]]></string>
<string name="ut"><![CDATA[%1$s μT]]></string>
现在,在Java中使用它们:
TextView txtMs = findViewById(R.id.txtMs);
String ms2 = String.format(getResources().getString(R.string.ms), "2.8");
txtMs.setText(Html.fromHtml(ms2));
TextView txtUt = findViewById(R.id.txtUt);
String ut = String.format(getResources().getString(R.string.ut), "2000.0");
txtUt.setText(Html.fromHtml(ut));
结果: