要绘制下面的TextView的Andr​​oid中的下划线 [英] To draw an Underline below the TextView in Android

查看:130
本文介绍了要绘制下面的TextView的Andr​​oid中的下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请我下面的的TextView 下划线。我寻觅了一些内容,但找不到任何东西卓有成效的。

I want to draw the underline below my TextView. I have searched a few content but couldn't find out anything fruitful.

任何人都可以请帮我在这里?

Can anyone please help me out here?

推荐答案

有三种方式中的TextView下属的文字。

There are three ways of underling the text in TextView.

  1. <一个href="http://developer.android.com/reference/android/text/SpannableString.html">SpannableString

<一个href="http://developer.android.com/reference/android/widget/TextView.html#setPaintFlags%28int%29">setPaintFlags(); TextView中的

setPaintFlags(); of TextView

<一个href="http://developer.android.com/reference/android/text/Html.html#fromHtml%28java.lang.String%29">Html.fromHtml();

让我解释一下你的所有方法:

Let me explain you all approaches :

1日法

有关在TextView中下属的文字,你必须使用<一个href="http://developer.android.com/reference/android/text/SpannableString.html">SpannableString

For underling the text in TextView you have to use SpannableString

String udata="Underlined Text";
SpannableString content = new SpannableString(udata);
content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
mTextView.setText(content);

2日法

您可以使用<一个href="http://developer.android.com/reference/android/widget/TextView.html#setPaintFlags%28int%29">setPaintFlags TextView中的方法强调的TextView的文本。

You can make use of setPaintFlags method of TextView to underline the text of TextView.

有关,例如。

mTextView.setPaintFlags(mTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTextView.setText("This text will be underlined");

您可以参考的常量,如果你想打这个文本涂料类。

第三个方法

请使用 Html.fromHtml的(htmlString);

String htmlString="<u>This text will be underlined</u>";
mTextView.setText(Html.fromHtml(htmlString));

这篇关于要绘制下面的TextView的Andr​​oid中的下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆