我有一个文本视图,我希望在普通的fontSize ( textview )中显示0.0,然后以较小的文本大小显示StringResult()。
如果我加上"0.0“+它不起作用。为什么?
public String StringResult(){
String displayLbl = this.getResources().getString(R.string.displayLbl);
TextView myUnitLbl = (TextView)findViewById(R.id.lbl_unit_res);
String myFinalLbl = displayLbl + " " + myUnitLbl.getText() + " ";
return myFinalLbl;
}
public void cmd_rst(View v){
TextView lblText = (TextView) findViewById(R.id.lblresult);
lblText.setText("0.0" + Html.fromHtml("<small>" + StringResult() + "</small>"));
}发布于 2013-11-21 20:38:07
这是因为当您尝试用"0.0“连接从Html.fromHtml返回的Html.fromHtml时,它会被用作一个普通字符串(从而放松任何格式设置)。要使此工作,请将所有内容传递到fromHtml
Html.fromHtml("0.0<small>" + StringResult() + "</small>")同样的原则也适用于更复杂的情况:
lblResult.setText(Html.fromHtml(String.format("%.1f", myCalc) + " " + "<br>" +
"<small>" + StringResult() + "</small>"));发布于 2015-08-31 11:03:13
只是
Html.fromHtml("0.0<small>" + StringResult() + "</small>")变到
Html.fromHtml("0.0<small>" + StringResult() + "</small>").toString()因为fromHtml()方法接受跨类型的参数,而不是字符串类型。
https://stackoverflow.com/questions/20131256
复制相似问题