Pergunta

I want to symbolize a space in an Android Button so:

  1. in the strings.xml file I define <string name="SpaceSymbol">␣</string>
  2. in the layout XML file I set android:text to "@string/SpaceSymbol"

When I run the application the button shows nothing. Any ideas? If any other character that symbolizes a space works other than ␣ I'll be glad to use it

Foi útil?

Solução 2

You can wrap the space char in ![CDATA[ ... ]] in the string resource..that may help you bring it in. You should check that the character is in the roboto font also

Given that the character is not represented in the Roboto font, you can use a SpannableString to replace the special character with your own image:

you should create a Drawable (or Bitmap) with the space image in it that you want to use. in this example it would be assigned to the variable 'drawable':

  SpannableString textspan = new SpannableString(sb);
  Pattern pattern = Pattern.compile("#_", Pattern.CASE_INSENSITIVE);
  matcher = pattern.matcher(textspan);
  while(matcher.find()) {
       textspan.setSpan(new ImageSpan(this, drawable, ImageSpan.ALIGN_BASELINE), matcher.start(), matcher.end(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  }

In your string (in this code example) you would have replaced your space symbol with the two characters "#_". The pattern will find each occurence of "#_" and replace it with the drawable.

Then you can use the SpannableString as a CharSequence argument anywhere it's defined (Toast.makeText, TextView.setText, etc) like this :

TextView tv = (TextView) findViewById(..);
tv.setText(textspan);

Outras dicas

Use the Html code corresponding to character, HTML Codes Table or HTML Special Characters

the define into the strings.xml

 <string name="SpaceSymbol">&#9251;</string>

This is an example with & character: How can I write character & in android strings.xml

Update:

Answering your question, is non-printable character, it is just a "Space", if you want show this symbol into the button, try loading an image of that symbol into an ImageButton.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top