为什么要使用的strings.xml Android中? [英] Why to use strings.xml in Android?
问题描述
任何人都可以请解释为什么有硬codeD字符串是如此糟糕? 我希望,如果我硬code弦哪些问题? 为什么有一个单独的XML字符串的文件解决这些问题?
Could anyone please explain why having hard-coded strings is so bad? What issues should I expect if I hardcode strings? Why having a separate string xml file solves those issues?
在strings.xml中创建新的元素是这样一个耗时的活动。
Creating new elements in strings.xml is such a time consuming activity.
推荐答案
当你添加字符串的strings.xml
,您可以轻松地翻译您的整个应用程序成其他语言。
When adding your strings to strings.xml
, you can easily translate your whole app into other languages.
因此,文件夹中的值
你会的strings.xml
与此内容:
So in the folder values
you would have strings.xml
with this content:
<string name="hello">Hello</string>
在值-FR
A 的strings.xml
与此内容:
<string name="hello">Bonjour</string>
这可以节省你的的很多的工作,而不是该做硬codeD的方式:Android的自动选择基于用户的preferences正确的语言,而且你不必担心选择和显示这种语言。
This saves you a lot of work instead of doing this the hardcoded way: Android automatically selects the correct language based on user preferences, and you don't have to worry about selecting and displaying this language.
请仔细阅读本地化| Android开发者。
这篇关于为什么要使用的strings.xml Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!