我在 strings.xml 中定义了字符串:
<resources>
<string name="edit_student">Edit Student</string>
<string name="add_activity">Add Activity</string>
<string name="act_name">Activity</string>
</resources>
但是当我用 .. 引用它时
setTitle(R.string.add_activity);
..它因错误而失败。
add_activity cannot be resolved or is not a field
但是在另一个地方类似的声明效果很好
setTitle(R.string.edit_student);
第一个没有但第二个有什么问题?
最佳答案
您不能直接使用字符串资源。使用方法如下:
setTitle(context.getString(R.string.resource_name));
关于java - 字符串已定义但未解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6481864/