Dav*_*own 108 android underline textview
我想画下面的下划线TextView.我搜索了一些内容但却找不到任何有效的内容.
有人可以帮帮我吗?
Kar*_*iya 307
在TextView中有三种方法来支持文本.
让我向您解释所有方法:
第一种方法
对于TextView中的文本,您必须使用SpannableString
String udata="Underlined Text";
SpannableString content = new SpannableString(udata);
content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
mTextView.setText(content);
第二种方法
您可以使用TextView 的setPaintFlags方法为TextView的文本加下划线.
例如.
mTextView.setPaintFlags(mTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTextView.setText("This text will be underlined");
如果要通过文本进行敲击,可以引用Paint类的常量.
第三种方法
利用 Html.fromHtml(htmlString);
String htmlString="<u>This text will be underlined</u>";
mTextView.setText(Html.fromHtml(htmlString));
要么
txtView.setText(Html.fromHtml("<u>underlined</u> text"));
Sar*_*rpe 39
只需在string.xml资源文件中使用<u>标记包围文本
<string name="your_string"><u>Underlined text</u></string>
并在您的活动/片段中
mTextView.setText(R.string.your_string);
man*_*ani 15
它对我有用.
tv.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
小智 10
对于任何仍在看这个问题的人.这是一个超链接,但你可以修改它只是一个简单的下划线:
创建一个drawable(hyperlink_underline.xml):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:top="-10dp"
        android:left="-10dp"
        android:right="-10dp">
    <shape android:shape="rectangle">
      <solid android:color="@android:color/transparent"/>
      <stroke android:width="2dp"
              android:color="#3498db"/>
    </shape>
  </item>
</layer-list>
创建一个新的风格:
<style name="Hyperlink">
    <item name="android:textColor">#3498db</item>
    <item name="android:background">@drawable/hyperlink_underline</item>
  </style>
然后在TextView上使用此样式:
<TextView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    local:MvxBind="Text Id; Click ShowJobInfoCommand"
    style="@style/HyperLink"/>
一个简单且可持续的解决方案是创建一个图层列表并将其作为 TextView 的背景:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:left="-5dp"
        android:right="-5dp"
        android:top="-5dp">
        <shape>
            <stroke
                android:width="1.5dp"
                android:color="@color/colorAccent" />
        </shape>
    </item>
</layer-list>
| 归档时间: | 
 | 
| 查看次数: | 127735 次 | 
| 最近记录: |