To draw an Underline below the TextView in Android

There are three ways of underling the text in TextView. SpannableString setPaintFlags(); of TextView Html.fromHtml(); 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 … Read more

Changing Underline color

There’s now a new css3 property for this: text-decoration-color So you can now have text in one color and a text-decoration underline – in a different color… without needing an extra ‘wrap’ element p { text-decoration: underline; -webkit-text-decoration-color: red; /* safari still uses vendor prefix */ text-decoration-color: red; } <p>black text with red underline in … Read more

Remove underline from links in TextView – Android

You can do it in code by finding and replacing the URLSpan instances with versions that don’t underline. After you call Linkify.addLinks(), call the function stripUnderlines() pasted below on each of your TextViews: private void stripUnderlines(TextView textView) { Spannable s = new SpannableString(textView.getText()); URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class); for (URLSpan span: spans) { int … Read more

Underline text in UIlabel

You may subclass from UILabel and override drawRect method: – (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(ctx, 207.0f/255.0f, 91.0f/255.0f, 44.0f/255.0f, 1.0f); // RGBA CGContextSetLineWidth(ctx, 1.0f); CGContextMoveToPoint(ctx, 0, self.bounds.size.height – 1); CGContextAddLineToPoint(ctx, self.bounds.size.width, self.bounds.size.height – 1); CGContextStrokePath(ctx); [super drawRect:rect]; } UPD: As of iOS 6 Apple added NSAttributedString support for UILabel, so now it’s much easier … Read more