user7913931
user7913931

Reputation:

TextView Bold the second line

I don't know if that's possibole or not, but i'm trying to achieve some thing like this :

enter image description here

Second line is bold, what i already done :

enter image description here

<TextView
        android:id="@+id/checkIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/text"
        android:layout_below="@+id/text"
        android:layout_marginLeft="5dp"
        android:padding="2dp"
        android:text="Check-in Date \n 10-08-2017"
        android:drawableLeft="@drawable/ic_calendar"
        android:textColor="@color/hintColor"
        android:drawablePadding="2dp"
        android:transitionName="price"
        android:textSize="@dimen/textInfoSmall" />

Upvotes: 1

Views: 971

Answers (3)

nhoxbypass
nhoxbypass

Reputation: 10152

I think the better practice is separate it into two TextView wrapped inside an Layout.

Because the texts "Check-in Date" and "Check-out Date" is always static. So use separate TextView will reduce String concatenate (Eg: textView.setText("Check-in Date \n" + checkInDate);), and make the source easier to read and extend.

If you still want to highlight part of text in TextView, there is already an answered question here: Android - Highlight a Word In a TextView?. This is all about SpannableString.

Upvotes: 1

Arun Shankar
Arun Shankar

Reputation: 2593

You should either use two textviews or you can use

Textview tvcheckIn = (TextView) findViewById(R.id.checkIn);
tvcheckIn.setText( Html.fromHtml("First Line<br><b>Second Line"));

Upvotes: 1

Nishin Raj
Nishin Raj

Reputation: 121

Simple way is to Use two TextViews

Or try SpannableString as explained here

How to make part of the text Bold in android at runtime?

Upvotes: 2

Related Questions