Android: underline text in your app

When I need to underline text in an app that I’m developing, I like doing it programmatically. The code is in the Java file, not in the XML.

Maybe we should make a function for this where we pass the ID of the TextView whose content we’d like to underline.

Disadvantages in this method:

  • It’s done in the Java file, not in UI files such as XML. It makes more sense to add codes for styling in XML files to me.
  • This underlines all text in the TextView. What if we need to underline only one text in a paragraph?

If you have any suggestion, feel free to comment. 🙂

// EDIT:

Here’s a method I prepared to make underlining TextView values easier:

public void setTextViewUnderline(TextView myTextView){
String htmlString = “” + myTextView.getText() + ““;
myTextView.setText(Html.fromHtml(htmlString));
}

Related Posts:

Posts that may be related to "Android: underline text in your app":

Catzie

A Filipino programmer with a variety of interests such as baking, singing, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert flavors, obsessing about finding out how some things works, board games, anime, video games, and forgetting things that usually go in her long list of interests. Running small-time online dessert shops Cookies PH and Catzie's Cakery.

Leave a Reply

Your email address will not be published. Required fields are marked *