Another time-saver! Creating String resources directly from Code editor

Write a string literal in your code like

mButton.setText("Text to add as String resource");

Then select the string literal  like this:


and press ALT+SHIFT+A, a yellow menu will appear in the bottom-right corner,


double click on “Extract Android String” , this menu will appear:


choose a proper name for the String resource and click Ok.

You will get a new strings.xml entry:

   <string name="my_string_resource">Text to add as string resource</string>

And your Button’s setText line replaced by:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s