【问题标题】:TextView Bold the second lineTextView 加粗第二行
【发布时间】:2018-01-13 21:15:08
【问题描述】:

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

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

<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" />

【问题讨论】:

    标签: android textview


    【解决方案1】:

    我认为更好的做法是将它分成两个 TextView 包裹在一个布局中。

    因为文本“入住日期”和“退房日期”始终是静态的。所以使用单独的TextView会减少String concatenate(例如:textView.setText("Check-in Date \n" + checkInDate);),并使源代码更易于阅读和扩展。

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

    【讨论】:

      【解决方案2】:

      你应该使用两个文本视图或者你可以使用

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

      【讨论】:

      • 好吧,我会试试你的解决方案,我认为这对我的情况很有用。
      【解决方案3】:

      简单的方法是使用两个TextViews

      或者按照此处的说明尝试 SpannableString

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-08
        • 2017-01-23
        • 2022-11-27
        • 1970-01-01
        • 2021-03-27
        • 2011-12-04
        相关资源
        最近更新 更多