getString Outside of a Context or Activity

后端 未结 12 1991
遥遥无期
遥遥无期 2020-11-28 01:12

I\'ve found the R.string pretty awesome for keeping hardcoded strings out of my code, and I\'d like to keep using it in a utility class that works with models i

12条回答
  •  有刺的猬
    2020-11-28 01:53

    Yes, we can access resources without using `Context`

    You can use:

    Resources.getSystem().getString(android.R.string.somecommonstuff)
    

    ... everywhere in your application, even in static constants declarations. Unfortunately, it supports the system resources only.

    For local resources use this solution. It is not trivial, but it works.

提交回复
热议问题