I try to do that in the text displayed in TextView, it was "It is necessary to XXX rub." But XXX should be red.
I try this:
public void onButtonClick (View v) { TextView Total = (TextView) findViewById(R.id.result); float Sum = (Tank-FuelCurrent)*PriceFl; String sSum = String.format("%.0f", Sum); SpannableStringBuilder ssb = new SpannableStringBuilder(sSum); ssb.setSpan(new ForegroundColorSpan(Color.RED), 0, sSum.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Total.setText("Необходимо "+ssb+" руб."); } Prints the entire line in one default color. If I change to
Total.setText(ssb); then, accordingly, only the price is displayed and displayed as it should, in red. I'm testing on a device with Android 4.2.2. How to correctly concatenate the result with a string?
