[Solved] AS Warning: String literal in setText can not be translated. Use Android resources instead.

error

String literal in setText can not be translated. Use Android resources instead.

Cause of

When the TextView object refers to the setText method, the string is directly passed in.

Example

        TextView textView = new TextView(this);
        textView.setText("text");    // Error: String literal in setText can not be translated. Use Android resources instead.

【Solution】

1. Add strings to the strings.xml file in the values ​​folder in the res folder.

<resources>
<string name="txtText">text</string>
</resources>

2. When the TextView object references the setText method, pass in the getString method.

        TextView textView = new TextView(this);
        textView.setText(getString(R.string.txtText));

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *