Do externalized strings need to be in strings.xml? - android

When I right-click on my project in Eclipse, and select "Externalize Strings" the wizard ends up putting the strings in a new "messges.properties" file; shouldn't it go in /res/values/strings.xml, or does it matter?

"Externalize Strings" is a standard functionality that is implemented in eclipse to work with java. If you want to extract Android string you should simply select the string, press ctrl+1 and in the appeared menu choose "Extract String" with the Android picture near this option.

Related

Is there a way to search by string previews in Android Studio?

I have a class which contains alot of string resources. I would like to search (Ctrl + F) particular string preview. For example
getString(R.string.transfer_label);
which is shown in intellij IDEA as string resources value
"TRANSFER"
So when i press CTRL+F and type "TRANSFER" naturally nothing happens. Is there any other shortcut that allows it? or any existing plugin?
Edit: I am looking for solution which works like CTRL+F one. I mean you type in something and it instantly moves you to place in code where its used. Making it very quick.
I normally go in my strings.xml and use "Find usage" (Alt + F7) on a string resource. This is the only way I know.
If your key Map is Default- cntrl+shift+F
If you want change the keys and key maps go here
Android Studio -> File ->Settings > KeyMap
Please find the below image for reference :
You can search in search bar what you are looking for

Creating a string constant to ALL language strings.xml in Android Studio

When I have to make a new string constant in a project I often use to simply write down the reference first just like: R.sring.my_new_string then I use Alt + Enter to pop up this dialog:
The problem is, as you can see only the default 'values' is selected when the dialog pops and I have to select the other 'values-it' (Italian strings) manualy to create the same string resource to that file too.
Of course this results in a deficient 'values-it/strings.xml' file because a lot of times I simply forget to select the checkbox.
Is there a way to somehow set Android Studio to always create the string resource for EVERY strings.xml in the project?
Thanks in advance
Press that to select all.
That doesn't solve your problem?
Happy coding!

Android: resource String automatic generation

I'm new to Android. When I add a button/views in Graphical layout it adds the label text this way- android:text="Button" . Why doesnt it add "android:text="#string/my_label" and add a string resource in string.xml file. Can't it be done automatically in eclipse?
I have searched a lot but I have not get any automated way to add a string to the resource file But This will save your time a lot IMHO.
Select a String, click Refactor --> Android --> Extract Android String.
Thanks to Brent Hronik. CTRL-1 on Windows works fine.
Because you don't have to use the #string resource. The purpose of the #strings resource is to make it easier to change elements about your code. For example, if you are using your application title in mutliple places, let's say in every dialog box, then if you change the title you would have to change it in all the instances that the app title is being display. So in this instance the #string/App_Title could be set to "My Program" and all of the dialog boxes can reference that. If you change the title to "Hello World" then all of these are changed. The #strings resource, while eclipse tries, doesn't have to be used for every string. Not using it is the equivalent to hard coding the value. There are plenty of reasons for and against using #string for everything.
I am not sure if there is a setting in eclipse that will automatically add a string to the resource file when the control is added.
(EDIT: Based on other users CTRL+1 is the short cut to do this.)
You can add the string to the strings.xml by clicking command and 1(on a mac, assume it would be control 1 on a Windows or Linux box) simultaneously. This will add the resource to strings.xml and then open that up in the editor.
Thanks Siddiq Abu Bakkar! I didn't think it would be there.
On Eclipse (and Windows) the shortcut is:
Alt+Shift+A (release all and then press) S
When you use Eclipse for first time it's not easy understand how to use these kind of "complex" shortcuts.
I can't vote and i can't comment answers yet (missing reputation as i'm a new user)
But i confirm :
1) hard type the string in your code like
mydlg.setTitle("hello guys");
2) select your string (e.g : "hello guys")
3) press Alt + Shift + A then press S
a dialog will appear to let you add a new string into resources. Everything should be already filled into that dialog box.

Is there way for extracting string resources in Android project in IntelliJ IDE?

When I'm working on Android project I would like to use some magic shortcut that would extract my string to strings.xml and also allow me to change the key. Is there any?
If there isn't, is there a way to develop new refactorization methods and extend IntelliJ possibilities?
Alt+Enter (to invoke intention action menu) on a string, then use Add a string resource action from the menu.
To rename resource use Refactor | Rename while standing on a resource name in Java code, it will rename all the references and the resource itself.
There is the Eclipse's option: Source / Externalize strings, which externalizes the strings of a class into a .properties file, but it does not seem to be able to export them directly to strings.xml in the Android way.
If you're using eclipse, you can highlight the string you want extracted to strings.xml, press Alt + Shift + A and in the small pop-up on the lower right of the screen select "Extract Android String"

Automatic Code Generation for Strings.xml from Eclipse

I find it a waste of time that every time I need to enter a string that I have to go edit the strings.xml file manually. What I'd like to be able to do ideally is have Eclipse pop up a dialog box that lets me specify the name of the resource and the value for it. Then Eclipse would generate the code in strings.xml and paste the correct reference to the string at the cursor position.
Does such a facility exist?
Select a String, click Refactor --> Android --> Extract Android String.

Categories

Resources