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?
There are three ways of underling the text in TextView.
setPaintFlags(); of TextView
Let me explain you all approaches :
1st Approach
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);
2nd Approach
You can make use of setPaintFlags method of TextView to underline the text of TextView.
For eg.
mTextView.setPaintFlags(mTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTextView.setText("This text will be underlined");
You can refer constants of Paint class if you want to strike thru the text.
3rd Approach
Make use of Html.fromHtml(htmlString);
String htmlString="<u>This text will be underlined</u>";
mTextView.setText(Html.fromHtml(htmlString));
OR
txtView.setText(Html.fromHtml("<u>underlined</u> text"));