1. 程式人生 > >Android TextView部分文字指定顏色

Android TextView部分文字指定顏色



String sm = "本功能為增值稅0申報,請確認您是否進行增值稅0申報?\n確認無誤後,請點選下方“確認申報”按鈕。";
<pre name="code" class="java">zTextView = (TextView) findViewById(R.id.zzs0sb_sm);
SpannableStringBuilder ssb = new SpannableStringBuilder(sm);
ssb.setSpan(new ForegroundColorSpan(Color.RED), 4, 10,
				Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
ssb.setSpan(new ForegroundColorSpan(Color.RED), 19, 25,
				Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
zTextView.setText(ssb);