我们都知道,Android中在一个Activity或是service中可以用this.getString(R.string,test);来获取字符串,但如果这样呢?
publicclass myTestClass{ public static
final String MYTEST = "this is a
test"; //如果这个字符串是在string.xml中,该如何获取该值
//this.getString()无法获取
}
如果你想要系统级别的,可以这样.
Resources.getSystem().getString(android.R.string.xxxxxx);
android.R.string.xxxxxx 为系统中已经定义的资源.
自己实现/重载 getString() 方法
你得传入一个上下文context啊
可以传个Resources进去,或者用个工具类继承Application,弄一个全局的Context(单例),并在XML中的Application中声明,类似与这样 android:name="test"
从构造函数中传入Context对象或者Resource对象即可。