Hardcoded string should use @string resource 警告

在布局文件中,文本的设置使用如下写法时会有警告:Hardcoded string "下一步", should use @string resource

<Button
        android:id="@+id/button1"
        android:layout_width="118dp" 
        android:layout_height="wrap_content"
        android:text="下一步" />

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

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="message">下一步</string>
</resources>

引用的时候使用

android:text="@string/message"

就行了。这样做可以做到一改全改,在支持多语言时也是很有用的。另外,颜色的设置也最好在color.xm中类似设置。

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/10018290.html
今日推荐