Android:R.string.xx 转为字符型

字符串资源定义示例:



    Hello World!


1. 在 Layout XML 调用字符串资源:


    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

    android:text="@string/hello" />

2. 在 Activity 获取字符串资源:

this.getString(R.string.hello)

3. 从 Context 获取字符串资源:

context.getResources().getString(R.string.hello)

4. 从 Application 获取字符串资源:

application.getString(R.string.hello)


举例:

// code inside an Activity method
String helloWorld = this.getResources().getString(R.string.hello_world);
int anInt = this.getResources().getInteger(R.integer.an_int);


你可能感兴趣的:(android)