加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Hardcoded string "???", should use @string r

发布时间:2020-12-16 04:58:46 所属栏目:百科 来源:网络整理
导读:在布局文件中,文本的设置使用如下写法时会有警告:Hardcoded string "下一步",should use @string resource [html] view plain copy Button android:id = "@+id/button1" android:layout_width = "118dp" android:layout_height = "wrap_content" android:t

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

[html] view plain copy
  1. <Button
  2. android:id="@+id/button1"
  3. android:layout_width="118dp"
  4. android:layout_height="wrap_content"
  5. android:text="下一步"/>"
虽然可以正常运行,但是这不是一个好习惯(如果你有个string="确定"在多个地方都用到,但是后来你想把它改为“确认”,你觉得是找到引用它的地方一个个改方便呢,还是直接在strings.xml里面改一处方便?你只看到了strings中增加了一条记录),应该在res/values/strings.xml中设置:
copy
    <?xmlversion="1.0"encoding="utf-8"?>
  1. resources>
  2. stringname="message">下一步</string>
  3. >
引用的时候使用
android:text="@string/message"
就行了。这样做可以做到一改全改,在支持多语言时也是很有用的。另外,颜色的设置也最好在color.xm中类似设置。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读