问题

I got an error message that says:

[I18N] Hardcoded string "Today - Sunny - 78/67", should use @string

resource.

How can this error be resolved?

The line of code is: android:text="Today - Sunny - 78/67"

回答1:

i18n is an abbreviation for internationalization. Android Studio is just giving you a hint that the way you are setting the text won't allow you to easily translate it.

Instead you should put your string in a strings.xml file within the res/values folder:

Today - Sunny - 78/67

You then reference that string on your TextView like this:

android:text="@string/my_string"

This would allow you to make another file for spanish strings, res/values-es/strings.xml that you could add a translation to:

Hoy - Soleado - 78/67

And then that string will automatically get picked for your TextView if the user's locale language is Spanish.

回答2:

It's implying that you should not explicitly write your text in your XML. You should use the /Values/Strings.xml to hold your string values.

Take a look through the folders on the left side, for values. The file is already there. You just need to add your string to it.

For the record, this doesn't normally generate an error of the "I'm gonna crash now" variety. It's usually just a warning.

回答3:

you can put mouse on problems line and use android studio hot key - alt+enter. After that you can choose "Extract string resource"

Sory fo my bad english =)

来源:https://stackoverflow.com/questions/31997616/android-studio-error-message-i18n

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐