TextView에 다른 색 입히기

유시현·2023년 1월 2일
0

Android

목록 보기
15/34

1. SpannableStringBuilder

String str = "글자를 바꿔주세요";
SpannableStringBuilder ssb = new SpannableStringBuilder(str);
ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#011FF6")), 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ssb);

2. HTML

<resources>
    <string name="app_name">TextViewDifferenceColor</string>
    <string name="text_message">
        <![CDATA[<font color="red">Hi</font>,
        <h1>Android</h1>]]>
    </string>
</resources>

string.xml

String text = getResources().getString(R.string.text_message);
textView.setText(Html.fromHtml(text));
profile
안드로이드 ,ios 공부하고 있습니다

0개의 댓글