How to extract string resource in Android studio

When working on an Android project, you use lots of strings in Activity/Fragments/Composable. As per official guidelines, and to take benefit of internationalization, you should not use hardcoded strings in your app. Rather, you should use string resources from res/values/strings.

But Going to the string resource file, making an entry there, and then using that resource in the code is a cumbersome task. If your code contains a lot of strings, this is a huge nuisance.

However, this can be avoided by taking a simple yet effective approach.

Wherever you have string literal in code,

1. Press Alt+Enter to open context menu and select Extract string resource

2. Type the name of the resource and press Enter.

3. Android Studio will take the string literal and turn it into a string resource, which it will then replace in your code.

Share with your friends

Leave a Reply

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