Issue
According to documentation unicode characters should be used with \u prefix in strings.xml file. For example use \u00a9 instead of ©.
<string name="copyright_text">Copyrighted ©</string>
But if I write © directly it seems to work fine even in API 21. Is there any scenario where it is really needed to scape other than other more impactfull characters such ash &, < >, etc.?
Solution
I don't have a definitive authority to point to, but in my own personal experience the only reason I have found to use the \u notation is when the character is visually ambiguous. For example, I use \u2013 instead of an actual en-dash character "–" because the glyph is so visually similar to the standard hyphen "-". Another common scenario is using \u00a0 instead of an actual non-breaking space character.
As far as I am aware, there is no technical reason to not use unicode characters in your strings file, as long as the file itself is using a character encoding that supports them.
Note that Android Studio's lint feature will actually prompt you to use these special characters in certain scenarios:
Applying the suggested fix leaves you with an ellipsis character "…", not the encoding for one.
Answered By - Ben P.

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.