Access string.xml Resource File from Java Android Code

前端 未结 5 1376
误落风尘
误落风尘 2021-01-30 12:25

How do you access the values in the res/values/string.xml resource file from the Android Activity class?

5条回答
  •  [愿得一人]
    2021-01-30 12:36

    If you have the context of Activity, go with:

    getString(R.string.app_name);
    

    If you don't have the context, try below, you can get the context from activity using Constructor.

    mContext.getString(R.string.app_name);
    

提交回复
热议问题