代码之家  ›  专栏  ›  技术社区  ›  user7913931

文本视图加粗第二行

  •  1
  • user7913931  · 技术社区  · 9 年前

    我不知道这是否可行,但我正在努力实现这样的目标:

    enter image description here

    第二行是粗体的,我已经做了:

    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" />
    
    3 回复  |  直到 9 年前
        1
  •  2
  •   Nishin Raj    9 年前

    简单的方法是使用两个文本视图

    或者试试这里解释的SpannableString

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

        2
  •  1
  •   Arun Shankar    9 年前

    Textview tvcheckIn = (TextView) findViewById(R.id.checkIn);
    tvcheckIn.setText( Html.fromHtml("First Line<br><b>Second Line"));
    
        3
  •  1
  •   nhoxbypass    9 年前

    我认为更好的做法是将其分为两个文本视图,并封装在一个布局中。

    因为文本“入住日期”和“退房日期”总是静态的。因此,使用单独的文本视图将减少字符串连接(例如: textView.setText("Check-in Date \n" + checkInDate);

    如果您仍想在TextView中突出显示部分文本,这里已经有一个已回答的问题: Android - Highlight a Word In a TextView? . SpannableString .