A ListView
in my application has many string elements like name
, experience
, date of joining
, etc. I just want to make name
bold. All the string elements will be in a single TextView
.
my XML
:
<ImageView android:id="@+id/logo" android:layout_width="55dp" android:layout_height="55dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="15dp" > </ImageView> <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/logo" android:padding="5dp" android:textSize="12dp" > </TextView>
My code to set the TextView of the ListView item:
holder.text.setText(name + "\n" + expirience + " " + dateOfJoininf);
android:textStyle attribute is the first and one of the best way to make the text in TextView bold. just use “bold”. If you want to use bold and italic. Use pipeline symbol “|” .
text. style. StyleSpan(Typeface. BOLD), start, end, Spannable.
Change Text Style of TextView to BOLD in XML Layout File textStyle attribute of TextView widget accepts on of these values: "bold" , "italic" or "normal" . To change the style to bold, you have to assign textStyle with "bold" .
Let's say you have a TextView
called etx
. You would then use the following code:
final SpannableStringBuilder sb = new SpannableStringBuilder("HELLOO"); final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold final StyleSpan iss = new StyleSpan(android.graphics.Typeface.ITALIC); //Span to make text italic sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold sb.setSpan(iss, 4, 6, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make last 2 characters Italic etx.setText(sb);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With