hardcoded string “row three”, should use @string resource

前端 未结 5 1901
抹茶落季
抹茶落季 2020-11-30 18:39

I\'m a beginner android developer , I was trying to run this Linear Layout in eclipse :

             


        
5条回答
  •  余生分开走
    2020-11-30 19:16

    It is not good practice to hard code strings into your layout files. You should add them to a string resource file and then reference them from your layout.

    This allows you to update every occurrence of the word "Yellow" in all layouts at the same time by just editing your strings.xml file.

    It is also extremely useful for supporting multiple languages as a separate strings.xml file can be used for each supported language.

    example: XML file saved at res/values/strings.xml:

    
    
        Yellow
    
    

    This layout XML applies a string to a View:

    
    

    Similarly colors should be stored in colors.xml and then referenced by using @color/color_name

    
    
        #000000
    
    

提交回复
热议问题