There are a few options you can join for a TextView , in which I'll give you some examples .
This is the class whose content and markup can both be changed, considering it to be a more native approach.
SpannableStringBuilder texto = new SpannableStringBuilder();
texto.append("Jeitos de colocar ");
int start = texto.length();
texto.append("o texto negrito");
texto.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start,
texto.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
texto.append(" em um TextView");
textView.setText(texto);
Use some of the tags HTML to format used text in a TextView
.
String texto = "Jeitos de colocar <b>o texto negrito</b> em um TextView";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
textView.setText(Html.fromHtml(texto,Html.FROM_HTML_MODE_LEGACY));
} else {
textView.setText(Html.fromHtml(texto));
}
Parameters:
public static final int FROM_HTML_MODE_COMPACT = 63;
public static final int FROM_HTML_MODE_LEGACY = 0;
public static final int FROM_HTML_OPTION_USE_CSS_COLORS = 256;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = 32;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV = 16;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = 2;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST = 8;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = 4;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = 1;
public static final int TO_HTML_PARAGRAPH_LINES_CONSECUTIVE = 0;
public static final int TO_HTML_PARAGRAPH_LINES_INDIVIDUAL = 1;
The string features provide text strings for the application with style and optional text formatting.
string.xml
<resources>
...
...
<string name="TextoHtml">
Jeitos de colocar
<b>o texto negrito</b>
em um TextView
</string>
</resources>
main.java
textView.setText(getString(R.string.TextoHtml));