版权声明:本文为博主原创文章,商业转载请联系博主获得授权,非商业转载请注明出处,否则追究其法律责任。 https://blog.csdn.net/u013642500/article/details/80166941
转载请注明出处,原文链接:https://blog.csdn.net/u013642500/article/details/80166941
【错误】
String literal in setText can not be translated. Use Android resources instead.
【翻译】
在setText方法中的字符串文字不能被转换。使用Android资源代替之。
【造成原因】
在TextView对象引用setText方法时,直接传入字符串。
【举例】
TextView textView = new TextView(this);
textView.setText("text"); // 此处报错:String literal in setText can not be translated. Use Android resources instead.
【解决方法】
1、在res文件夹中的values文件夹中的strings.xml文件中添加字符串。
<resources>
<string name="txtText">text</string>
</resources>
2、在TextView对象引用setText方法时,传入getString方法。
TextView textView = new TextView(this);
textView.setText(getString(R.string.txtText));
【相关警告】
错误:Do not concatenate text displayed with setText. Use resource string with placeholders.
详见:https://blog.csdn.net/u013642500/article/details/80167402
【说明】
本文可能未必适用所有情形,本人尚属初学者,如有错误或疑问请评论提出,由衷感谢!