Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:21:13+00:00 2026-06-05T19:21:13+00:00

I am a bit confused about the ‘rules’ of when a TextView element displays

  • 0

I am a bit confused about the ‘rules’ of when a TextView element displays text in formatted form or not.

A string like

"There are <i>different ways</i> of coding.\n";

displays without any formatting (including the HTML codes) when I code

tvMyTextView.setText("There are <i>different ways</i> of coding.\n");

but when I define the same string in strings.xml and then load

tvMyTextView.setText(R.strings.TestString);

it displays emphasized.

Even more confused I feel when trying to embed URLs in TextView’s like here:

"Click <a href="http://www.poon-world.com">here</a> to switch on the red light.\n";

Needless to say I already tried the various property options of TextView – but they don’t seem to make much of a difference unless I missed something. In some cases the URL is encoded in the text, in blue color and can be clicked, in others I can see the HTML formatting. In others again, it is color-encoded and the URL seems to be encoded in the text somehow – but nothing happens when I click it. Regarding the embedding of URLs, unlike for the other example with ‘simple’ HTML formatting, I couldn’t even find out a rule so far of when it works and when it doesn’t. Can anyone help me to untie the knots in my head..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:21:14+00:00Added an answer on June 5, 2026 at 7:21 pm

    Actually, From the Android Docs..

    public final void setText (CharSequence text)
    

    Sets the string value of the TextView. TextView does not accept HTML-like formatting, which you can do with text strings in XML resource files. To style your strings, attach android.text.style.* objects to a SpannableString, or see the Available Resource Types documentation for an example of setting formatted text in the XML resource file.

    But,

    public final void setText (int resid)
    
    • no more specification on it..

    But from Android Resource String docs..

    You can add styling to your strings with HTML markup. For example:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="welcome">Welcome to <b>Android</b>!</string>
    </resources>
    

    Supported HTML elements include:

    <b> for bold text.
    <i> for italic text.
    <u> for underline text.
    

    Sometimes you may want to create a styled text resource that is also used as a format string. Normally, this won’t work because the String.format(String, Object...) method will strip all the style information from the string. The work-around to this is to write the HTML tags with escaped entities, which are then recovered with fromHtml(String), after the formatting takes place.

    And about your URL string,…

    tvMyTextView.setText(Html.fromHtml("Click <a href="http://www.poon-world.com">here</a> to switch on the red light.\n"));
    

    Also look at this SO Question Set TextView text from html-formatted string resource in XML

    and

    Android String Resource

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not
I am bit confused about the Full Text search in SQL Server 2005/2008. What
I'm a bit confused about Eclipse release 3.8 It seems a bit like a
I'm a bit confused about how many controllers I need, and when I can
I'm a bit confused about the use of all the IEnumerable<T> extension methods, intellisense
I am a little bit confused about 2 things. Firstly when I create an
I'm a bit confused about how to overload the stream operators for my class
I am a bit confused about this. If you're building a distributed application, which
I'm a bit confused about handling an array of objects in C++, as I
I'm a bit confused about the object references. Please check the examples below: class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.