2012-01-30 72 views
0

我仍然在学习Java,但我试图获得有关android操作系统的经验。 这段代码的问题在于,不是前两行是红色,最后一行是蓝色,所有行都是红色的。 有人可以帮我吗?Android TextView Html.fromHtml不工作?

package taco.potato; 

import android.app.Activity; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.text.Html; 
import android.widget.TextView; 

public class TacoActivity extends Activity { 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
TextView txt = new TextView(this); 
txt.setBackgroundColor(Color.BLUE); 
txt.setTextColor(Color.RED); 
txt.setText("Test1"); 
txt.append("\nTest2\n"); 
txt.append(Html.fromHtml("<p style = 'color:blue'>Test3</p>")); 
setContentView(txt); 
} 
} 

我试过删除txt.setTextColor,但后来一切都只是黑色。

+0

我认为.fromHtml方法会忽略样式属性,因为它只显示'基本'HTML。 – Demonick 2012-01-30 13:34:59

回答