android 开发之旅, should use @string resource警告

来源:互联网 发布:教跳舞的软件 编辑:程序博客网 时间:2024/05/16 17:36
在布局文件中,文本的设置使用如下写法时会有警告:Hardcoded string "BUTTON", should use @string resource
[html] view plaincopy
  1. <Button  
  2.         android:id="@+id/button1"  
  3.         android:layout_width="118dp"   
  4.         android:layout_height="wrap_content"  
  5.         android:text="button" />"  
虽然可以正常运行,但是这不是一个好习惯,应该在res/values/strings.xml中设置:
[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="message">button</string>  
  4. </resources>  
引用的时候使用
android:text="@string/message"
就行了。这样做可以做到一改全改,在支持多语言时也是很有用的。另外,颜色的设置也最好在color.xm中类似设置。

原创粉丝点击