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

strings.xml和@string的用法

发布时间:2020-12-15 22:35:39 所属栏目:百科 来源:网络整理
导读:1、layout的代码: TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FF0000" android:textSize="70px" android:text=" @string/hello " / 2、strings.xml的代码: ?xml version="1.0" encoding="u

1、layout的代码:

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:textSize="70px"
android:text=" @string/hello" />

2、strings.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">FirstProject</string>
<string name="hello">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>

解释:@string/hello指的是在strings.xml文件中定义的hello字符串,即hello字符串中存有“Hello world!”,并在界面中输出。这种用法在将引用程序本地化为另一种语言时用到。

3、stings.xml

用来存储应用程序中所有 字符串常量。这使得您可以很容易地通过替换这些字符串并重新编译应用程序来本地化您的应用程序

(编辑:李大同)

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

    推荐文章
      热点阅读