Access string.xml Resource File from Java Android Code

前端 未结 5 1379
误落风尘
误落风尘 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:41

    Well you can get String using,

    getString(R.string.app_name);
    

    And, you can get string-array using

    String arr[] = getResources().getStringArray(R.array.planet);
    for (int i = 0; i < arr.length; i++) {
            Toast.makeText(getBaseContext(),arr[i], Toast.LENGTH_LONG).show();  
    }
    

提交回复
热议问题