android 讀取資源字符串的 方法

字符串資源的定義

文件路徑: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)

參考:

String Resources

 

作者:黎波
博客:http://bobli.cnblogs.com/
日期:2011年6月4日
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章