Android中调用字符串资源的几种方法

l  字符串资源的定义

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

字符串资源定义示例:

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

 

l  字符串资源的调用

ü   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)

转至:http://blog.sina.com.cn/s/blog_a1d9904b01016had.html

你可能感兴趣的:(Android开发)