简体   繁体   中英

what happen if do not put text files in string.xml in android?

i did not put some text in string.xml and there is a yellow alert symbol in side of Textview field. i want to know does it have problem and what happen, if do not put texts in string.xml in android?

尽管短期内不会造成问题,但它不是一种好习惯,如果您决定支持多种语言,则将来会引起问题。

Well, setting your text directly on your layout file can be a source of future problems and its not recommended.

Consider this scenario: You use the same string "Foo" in many layout files and then you decided to change to "Bar". If you have hardcoded that, you will need to make changes in all layout files and there might be a chance to leave some inconsistent text. But if you place it in the strings.xml file, you will have only to change in one place.

Also, if you want to add translations to your app, the Android system can handle it automatically for you if you use the strings.xml .

You might want to take a look here and here .

Nothing will happen.

string.xml used to:

  1. localization res/values-fr/strings.xml res/values-ja/strings.xml
  2. ease of editing and to save memory when reusing.

I Recommend you to put text files in string.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM