How can I change the color, size and boldness of the text programmatically (via java-code) without resorting to android: textSize and android: color and at the same time creating new TextView each time? I use this method:

TextView text = (TextView)findViewById(R.id.textview1); text.setText("Простой текст") 

    3 answers 3

    1. Color: text.setTextColor(Color.RED);

    2. Size: text.setTextSize(100);

    3. Fatness: text.setTypeface(null, Typeface.BOLD);

    • Can I change the size of a single textview several times? T, is some part of the text of one size and the second part of the same textview of another size? - Vyacheslav
    • You can, through SpannableString, for example: mySpanString.setSpan (new RelativeSizeSpan (0.5f), from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); txt.setText (mySpanString); - Jarvis_J

    I correctly understood that you need this

     TextView textV = (TextView)findViewById(R.id.<id вашего TextView>); textV.setTextColor(Color.RED); textV.setBackgroundColor(Color.Black); 

    well, as below

     textV.setTextSize(100); textV.setTypeface(null, Typeface.BOLD); 

    etc. etc.

    • Can you change the font size and boldness in a similar way? - Vyacheslav
    • in this way, you can change anything, it is in many languages ​​like that - Yaroslav Prokhorov
    • And we can change this data only once or can we make a textview containing text of different sizes? - Vyacheslav
    • the data change is applied to the current object, if you specify a new format for the same object, it will usually erase the previous one as: x = 1, x = 3 -> answer x, at the end of the operation it will store 3 - Yaroslav Prokhorov

    Perhaps the author of the question had in mind within TextView to have text formatting. In this case, you can use:

     mytextview.setText(Html.fromHtml("Пример <b>моего текста</b>")); 

    It will look like this: An example of my text You can do almost anything with text.