0

I have this TextViews:

((TextView)findViewById(R.id.carmodel)).setText("CarModel: " + getCarModel+"");
((TextView)findViewById(R.id.bikemodel)).setText("BikeModel: " + getBikeModel+"");

Is there a way to make bold just CarModel: and BikeModel:?

This is the XML file:

<TextView
    android:id="@+id/carmodel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:textSize="17sp"
    android:textStyle="italic"
    android:layout_marginLeft="10dp"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
    android:id="@+id/bikemodel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:textSize="17sp"
    android:textStyle="italic"
    android:layout_marginLeft="10dp"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall" />

So the getCarModel and getBikeModel will be italic and the CarModel and BikeModel: bold.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Goro
  • 499
  • 1
  • 13
  • 31
  • 1
    Does this answer your question? [how to make a specific text on TextView BOLD](https://stackoverflow.com/questions/14371092/how-to-make-a-specific-text-on-textview-bold) – capo11 May 24 '21 at 09:39

1 Answers1

3

There are many ways to achieve what you want.

1) You can insert HTML inside your text view as explained by "Tanis" here "How to display HTML in TextView?"

((TextView)findViewById(R.id.carmodel)).setText(Html.fromHtml("<h2>CarModel: </h2>") + getCarModel+"");

2) You can create two text views like

((TextView)findViewById(R.id.carmodelBold)).setText("CarModel: ");    
((TextView)findViewById(R.id.carmodel)).setText(getCarModel);   

and style the text view with ID "carmodelBold" as you want.

3) You can create a table

Community
  • 1
  • 1
Ankit
  • 1,075
  • 1
  • 8
  • 19
  • May be the second way will help me but how to put them on one row? Because if I make one textview for bold text and another for data they are on different lines? – Goro Jan 09 '15 at 13:36
  • I believe you are using lineraLayout with vertical orientation. You need to use linearLayout with horizontal orientation. – Ankit Jan 09 '15 at 13:53
  • Just in case...You can nest layouts also. So if you cannot change the current layout, create a new layout inside it with desired orientation – Ankit Jan 09 '15 at 13:57
  • Yes, I'm using LinearLayout and if I change it to `horizontal` everything is hided.. any example how to make it with nested layouts? – Goro Jan 09 '15 at 14:03
  • check these links: http://stackoverflow.com/questions/24931904/not-able-to-align-two-text-views-on-the-same-line-in-android – Ankit Jan 09 '15 at 14:12
  • http://stackoverflow.com/questions/11927024/align-two-textviews-one-left-the-other-right-on-a-listview-without-stretching – Ankit Jan 09 '15 at 14:12
  • But what if I have 9-10 textviews ... I must wrap every one in `LinearLayout`? – Goro Jan 09 '15 at 14:16
  • You must use the 3rd option. Wrap them in a table. That would be neater way to implement. You can google how to implement TableLayout in Android. – Ankit Jan 09 '15 at 14:30
  • Ok, I will google it and try to make. Thank's for help so far – Goro Jan 09 '15 at 14:46