반응형
블로그 이미지
sense.45

공지사항

최근에 올라온 글

최근에 달린 댓글

글 보관함

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

How to Change the Text Color of a Substring

2018. 3. 20. 14:06 | Posted by sense.45
반응형

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