반응형
TextView textView = findViewById(R.id.text_view);
String text = 'I want THIS and THIS to be colored";
//SpannableString ss = new SpannableString(text);
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
ForegroundColorSpan fcsRed = new ForegroundColorSpan(Color.RED);
ForegroundColorSpan fcsGreen = new ForegroundColorSpan(Color.Green);
BackgroundColorSpan bcsYellow = new BackgroundColorSpan (Color.Green);
ssb.setSpan(fcsRed, 7,11, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(fcsGreen, 16,20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(fcsYellow, 27,34, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(" and this to be appended");
textView.setText(ssb);
원본:https://www.youtube.com/watch?v=tTLmz-JKxsI
반응형
'Android' 카테고리의 다른 글
안드로이드 WIFI 연결 체크 (0) | 2019.02.12 |
---|---|
안드로이드 Calendar.getInstance API level24 (0) | 2018.07.10 |
NFC NTAG 213 (1) | 2018.03.26 |