请看下面的代码
字符串.xml
<string name="measurements_description"><html><font color="#FFFAF0">I want to have white color for the whole text.
<br/>This text comes in a new line<font color="red">This text is red </font>
<br/>This is another line. Again, color is white </font></html></string>
male_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/measurementsDescription"
android:text="@string/measurements_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</ScrollView>
Form.java(这个属于主布局activity_form)
public boolean onMenuItemSelected(int id, MenuItem item) {
//Toast.makeText(this, item.getTitle(), Toast.LENGTH_LONG).show();
TextView msg = new TextView(this);
msg.setText("<html><u>Message</u></html>");
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
//alertBuilder.setMessage("<html><u>Message</u></html>");
alertBuilder.setTitle("Male Measurement Instructions");
LayoutInflater li = getLayoutInflater();
View v = li.inflate(R.layout.male_layout, null);
alertBuilder.setView(v);
alertBuilder.setCancelable(false);
alertBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
//alertBuilder.finish();
}
});
AlertDialog alertDialog = alertBuilder.create();
alertDialog.show();
return true;
}
这就是它的显示方式,而不响应 string.xml 文件中的任何 HTML。为什么这没有改变它在 HTML 中编码的颜色?为什么它不保持 HTML 中编码的换行符?
如何解决这个问题?请帮忙!