Android: is there an easy way to find all the Strings in my project?

前端 未结 6 1924
既然无缘
既然无缘 2021-02-19 15:49

I want to scan my Android project for all hardcoded Strings so I can localize the project, putting the Strings in strings.xml. I see an option in Eclipse to \'Externalize String

6条回答
  •  心在旅途
    2021-02-19 16:10

    Field[] fields = R.string.class.getDeclaredFields(); // or Field[] fields = R.string.class.getFields(); String str = ""; for (int i =0; i < fields.length; i++) { int resId = getResources().getIdentifier(fields[i].getName(), "string", getPackageName()); str += fields[i].getName() + " = "; if (resId != 0) { str += getResources().getString(resId); } str += "\n"; }

    You will get all codes of strings with its values in "str" variable.

提交回复
热议问题