2012-12-03 33 views
0

在我的Android應用程序..一個數由用戶輸入在不同條件下分配不同的顏色相同的TextView和我的應用程序告訴數量是否是在一個TextView整數或浮點數類型號的..! 我面臨的問題是,我要顯示整型數和綠色浮法.. 應該是什麼這樣的代碼中的紅色TextView的。我們怎樣才能像使用的EditText .. 如果...在其他的Android

的的if..else條件碼我要的是想象這樣的:

TextView tv = (TextView) findViewById(R.id.my_text_view); 
if (number= interger) 
{ 
tv.setText("integer number"); 
// and the color of this TextView will be RED 
} 
else 
{ 
tv.setText(Float number); 
// and the color of this TextView will be GREEN 
} 

謝謝。

回答

1

這樣的代碼:

tv.setText(Html.fromHtml("<font color='red'>integer</font> is <font color='blue'>number</font>")); 
0

這裏是您的資源預定義的顏色或定義的顏色的示例 textview.setTextColor(this.getResources()的getColor(R.color.orange)。);