呼叫字串資源的幾種方法

2022-02-06 09:05:34 字數 707 閱讀 6019

字串資源的定義

檔案路徑: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)

----以上**:

Android 呼叫字串資源的幾種方法

字串資源的定義 檔案路徑 res values strings.xml 字串資源定義示例 xml version 1.0 encoding utf 8 resources string name hello hello string resources 字串資源的呼叫 在 layout xml 呼叫...

Android 呼叫字串資源的幾種方法

字串資源的定義 檔案路徑 res values strings.xml 字串資源定義示例 xml version 1.0 encoding utf 8 resources string name hello hello string resources 字串資源的呼叫 在 layout xml 呼叫...

Android 呼叫字串資源的方法

字串資源的定義 檔案路徑 res values strings.xml 字串資源定義示例 xml version 1.0 encoding utf 8 resources string name hello hello 字串資源的呼叫 在 layout xml 呼叫字串資源 textview and...