2

Можно ли поменять цвет некоторых букв в самом string.xml или программно, как это можно сделать?

<string-array name="colors">
    <item>I read the letter.</item>
    <item>It is only with the heart that one can see rightl.</item>
    <item>One can become a writer only if he is talented.</item>
    <item>They say, the winter will be cold.</item>
</string-array>

1 ответ 1

2
<string-array name="colors">
        <item>
            <![CDATA[
               <font color="#005500">I</font> read the letter.
            ]]>
            </item>
        <item>It is only with the heart that one can see rightl.</item>
        <item>One can become a writer only if he is talented.</item>
        <item>They say, the winter will be cold.</item>
</string-array>  

Html.fromHtml(getResources().getStringArray(R.array.colors)[0])


Программно:

final SpannableStringBuilder text = new SpannableStringBuilder("Text");
final ForegroundColorSpan style = new ForegroundColorSpan(Color.rgb(255, 0, 0)); 
text.setSpan(style, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(text);

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.