How to extract string resource in Android studio (APG-17)

How to extract string resource in Android studio (APG-17)

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

No alt text provided for this image

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

No alt text provided for this image

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

#android?#androiddeveloper?#androiddevelopment?#androidstudio?#kotlin?#java


We also have an android developer community on WhatsApp where we enjoy learning and sharing everything android, including live sessions, interview preparation, job referral, tutorials, and Q&A. Join us if you're interested.

https://bit.ly/adc-whatsapp-1

https://bit.ly/adc-whatsapp-02?(Join this if the first group is full)

No alt text provided for this image

要查看或添加评论,请登录

Rajesh Hadiya的更多文章

社区洞察

其他会员也浏览了