Hardcoded string should use string resource android solved

Hardcoded string should use string resource android solved

Android should use string resource warning

After creating an android studio project and add any widgets a warning show up "Warning: Hardcoded string "TestButton" , should use '@string' resource" . this is not error it's just warning many of platforms use string resource to separate between code and resource as string , images ... so let's see how to fix this .

What is android string resource

android string resource is a simple xml file you can call it also a library , in this library you define all your string text and then in your android widget you just call a name to that text .

Where is string resource file

usually after create your android project your strings resource file located in "project name" - app - src - main - res - value - strings.xml . the file should be like this <resources></resources>

Watch Our YouTube Tutorial

How to add a string resource line

To add string resource , just add a new string inside your strings.xml file and write <string name="name">Value</string> , the name you can change it whatever you want it's the name you will call inside your android project and the Value is the display value , so let me make it easy for you if you call Name Mybutton and Value submit and you want change the Value of your button you only change Value and don't change Name .

How to call string resource

click inside your widget button or whatever , then click proprieties next go to text delete default text and double click inside input text a suggestion list will show up and show you all the defined string source just click in your preferred string and that is it we are done .

Leave comment