简体   繁体   中英

Why am I being asked to make my String in xml as @string reference?

@ string /参考错误

android:text="Button" doesn't work. I should make a special string for it in the values/strings.xml and change the android:text="Button" to android:text="@string/button" for button having the value "Button" .

What's the problem it used to work before?

Those are not error only warning, there is tool in every ide called lint which helps programmer to write code in standard format of that language. In android standard practice is to use string.xml for storing all of your string value that is used in xml, so lint shows a warning that you should not directly set label hard-coded rather add them in string resource then set the resource id.

And there is some advantage of using string values like

  • If you want to give multi language support of your app then can use multiple string resources for this.
  • Can be changed any time without changing source code.
  • All resource are added in R.java automatically so you can use them in class also.

etc

You can find more information here --

String Resources

hardcoded string "row three", should use @string resource

this answered my question, thank you, but if you have anything to add i'm glad to know it from you guys. Best.

Alan

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