如何在java代码中获取string.xml中的字符串

如题所述

获取string.xml文件里面的值有几个不同的地方。

1.在AndroidManifest.xml与layout等xml文件里:

android:text="@string/resource_name"

2.在activity里:

方法一:this.getString(R.string.resource_name);

方法二:getResources().getString(R.string.resource_name);

3.在其他java文件(必须有Context或pplication)

方法一:
context.getString(R.string.resource_name);
方法二: application.getString(R.string.resource_name);
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答