我在Android TextView中使用像这样的标记,
mNameStr = "<font color='#ff0000'>" + "myword" + "</font>";
result = Html.fromHtml(mNameStr, Html.FROM_HTML_MODE_LEGACY);
mName.setText(result);
但是,它不起作用。为什么?
答案 0 :(得分:1)
使用最简单的方法
myNameTV.setText( “myWord” 的);
myNameTV.setTextColor(Color.parseColor( “#fd0101”));
答案 1 :(得分:0)
试试这个
String mNameStr = " <font color=#ff0000> myword </font>";
mName.setText(Html.fromHtml(mNameStr), TextView.BufferType.SPANNABLE);
或试试这个
mName.setText(Html.fromHtml("<font color=\"#ff0000\">" + "myword " + "</font>"));
答案 2 :(得分:0)
mNameStr = "<font color=#ff0000>myword</font>";
mName.setText(Html.fromHtml(mNameStr));
正在检查此示例代码和附加的图像。
public class SampleActivity extends AppCompatActivity {
private TextView sampleText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
sampleText= (TextView) findViewById(R.id.sample);
String mNameStr = "<font color=#ff0000>myword</font>";
sampleText.setText(Html.fromHtml(mNameStr));
}
}