Skip to main content

Android and   in TextView ?

Android and   in TextView ?


A1. 

          The TextView should respect the non breaking space

    <string name="test">Hello&#160;world</string>

                                    or

        new TextView("Hello\u00A0world");

A2.

    One unique situation I ran into was adding a non-breaking space to a string resource that took              String.format parameters.


    <resources>
    <string name="answer_progress" formatted="false">Answered %d of %d</string>
    </resources>


      I tried to simply copy and past the non-breaking space character into the string and it was                     replaced       with a regular old space after compiling.
      Removing the formatted="false", numbering the format args and using the backslash notation               worked for me:

    <resources>
    <string name="answer_progress">Answered %1$d\u00A0of\u00A0%2$d</string>
    </resources>



A3.


   
   if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
    textview.setText(Html.fromHtml(your string, Html.FROM_HTML_MODE_LEGACY));
   } else {
    textview.setText(Html.fromHtml(your string);
    }












Comments