2

I want to bold the text which is inside ** . I am taking the text as input through EditText and than putting it in Text View similar to Whatsappex. hello *world*

Mirza Asad
  • 606
  • 1
  • 7
  • 18
  • Using **`SpannableString`** – AskNilesh Jan 31 '18 at 11:24
  • 1
    You could use `Html.fromHtml()` method to make text bold when displayed in `TextView`. To make part of a text bold, you can do it like this, `textView.setText(Html.fromHtml("Sample text with bold style"))` The text to make bold, you cant get by searching for `*` in the input text. `Html.fromHtml()` method returns `SpannableString` – josh_gom3z Jan 31 '18 at 11:36

1 Answers1

3

You can use this

SpannableStringBuilder str = new SpannableStringBuilder("Text here with * inside *");
str.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), INT_START, INT_END, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView tv=new TextView(context);
tv.setText(str);

where INT_START and INT_END will be the position of the *

Rudrik Patel
  • 676
  • 6
  • 13