[Android] TextView 특정 구간 글씨 조절 , 하나의 TextView(EditText)에 서로 다른 크기의 글씨 넣기
2021. 5. 4. 17:08ㆍ카테고리 없음
[Android] TextView 특정 구간 글씨 조절 , 하나의 TextView(EditText)에 서로 다른 크기의 글씨 넣기
내 구현
<Textview>
android:bufferType="spannable"
</Textview>
Spannable span = (Spannable) textview.getText();
span.setSpan(new ForegroundColorSpan(getResources().getColor(ColorValue)),0,28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color04)),28,39, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new ForegroundColorSpan(getResources().getColor(ColorValue)),39,tvLeverageGuide.getText().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
공식 문서 구현
SpannableStringBuilder spannable = new SpannableStringBuilder("Text is spantastic!");
spannable.setSpan(
new ForegroundColorSpan(Color.RED),
8, // start
12, // end
Spannable.SPAN_EXCLUSIVE_INCLUSIVE
);
BackgroundColorSpan
- 배경색 지정 가능
StyleSpan
- 스타일 지정 가능
더보기 : https://developer.android.com/guide/topics/text/spans?hl=ko