android 調用字符串資源 res/values/strings.xml 的幾種方法

字符串資源的定義

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章