Hardcoded string " ",should use @string resource警告

     在使用eclipse的在布局文件时,有时编辑一些控件的字符串名字中,有时会提示诸如“Hardcoded string "Next", should use @string resource”的警告,这是什么原因呢?

1 <Button
2 
3         android:id="@+id/button1"
4 
5         android:layout_width="118dp" 
6 
7         android:layout_height="wrap_content"
8 
9         android:text="Next" />

    虽然上述的做法可以正常运行,但是这不是一个好习惯,应该在res/values/strings.xml中设置:

1 <?xml version="1.0" encoding="utf-8"?>
2 
3 <resources>
4 
5     <string name="next">Next</string>
6 
7 </resources>

    引用的时候使用 :

1 <Button
2  
3          android:id="@+id/button1"
4  
5          android:layout_width="118dp" 
6  
7          android:layout_height="wrap_content"
8  
9          android:text="@string/next" />

     这样做可以做到一改全改,在支持多语言时也是很有用的。如果不想编辑strings.xml文件,则用layout框中,点击控件的textview项,new一个新的string名字,再在strings.xml对应的编辑框中完善这个字符串对应的内容就行了。

    eclipse中一次性导入用到的所有类

    使用组合键:ctrl+shift+o可以一次性导入所有需要import的类。

    重命名多处调用的文本对象 

    一个特定对象名字可能在一个java文件中多次被调用,如果要修改这个对象的名字,可以在eclipse中双击激活这个对象,会显示所有调用到的地方。然后右键选择refactor->rename即可。

    重命名包名

     APK应用工程文件夹的第一层名字,可以直接修改名字,右击工程,选择refactor->rename即可

猜你喜欢

转载自www.cnblogs.com/jachin19971218/p/10710425.html
今日推荐