0

私のAndroidアプリケーションでは、ユーザーがEditTextを使用して数値を入力します。アプリケーションは、その数値が整数型か浮動小数点型かをTextViewで通知します。私が直面している問題は、整数型の数値の場合は赤色で、浮動小数点数の場合は緑色でTextViewを表示したいということです。このためのコードは何である必要がありますか。

私が欲しい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
}

ありがとうございました。

4

2 に答える 2

1

次のようなコード:

tv.setText(Html.fromHtml("<font color='red'>integer</font> is <font color='blue'>number</font>"));
于 2012-12-03T15:22:07.750 に答える
0

リソースに定義済みの色または定義済みの色を使用した例を次に示します textview.setTextColor(this.getResources().getColor(R.color.orange));

于 2012-12-03T15:28:07.743 に答える