Chinaunix首页 | 论坛 | 博客
  • 博客访问: 130570
  • 博文数量: 30
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 338
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-19 17:33
文章分类
文章存档

2017年(2)

2014年(28)

我的朋友

分类: Android平台

2014-07-22 21:01:53

字符串资源的定义

文件路径:res/values/strings.xml

字符串资源定义示例:

xml version="1.0" encoding="utf-8"?>
<resources>
    
<string name="hello">Hello!string>
resources>

 

字符串资源的调用

在 Layout XML 调用字符串资源:

<TextView
    
android:layout_width="fill_parent"
    android:layout_height
="wrap_content"
    android:text
="@string/hello" />

 

在 Activity 获取字符串资源:

this.getString(R.string.hello)

 

从 Context 获取字符串资源:

context.getString(R.string.hello)

 

从 Application 获取字符串资源:

application.getString(R.string.hello)
阅读(1483) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~