Android studio beginner here. My professor is telling me to change the res/values/strings.xml in my application. The purpose of this is to add a Color definition to the file and then tells me to press an "Add" button. However, I'm having trouble actually accessing the same window he is...here is the window:
What I see when opening the strings.xml file is this:
There are no buttons for me to actually add a definition. I tried playing around with the strings.xml file by right clicking the file, but nothing really looks like anything I want.
Any help is appreciated!
My professor is telling me to change the res/values/strings.xml in my application.
Here you mention that you want to change the strings using Add button. In that case, you can do it as follows:
Click on Open Editor on the top right when your strings.xml is open.
Then you will see this new Window. Use + key to add a new string resource.
Your professor might have a different Android Studio version. This is how it shows in Android Studio 2.3.3 version.
The purpose of this is to add a Color definition to the file ...
Here you mention that you want to change the color definitions. If that's the case, you need to change in colors.xml. If a file is not there, then create one in values folder and add <color name="color_name">#HEX_VALUE</color>. Then you can reference the color from Java or XML file.
Just add another entry in your strings.xml file corresponding to what your requirement is, and save the file.
For example:
<resources>
<string name="app_name">Temperature Converter</string>
<string name="new_string_name">new_string_value</string>
</resources>
Related
I'm attempting to create a 'Preferences' Activity for my Wear OS app (home-baked as I don't believe the standard Settings Activity copes with round screens).
In order to support the round screen I am planning to use a WearableRecyclerView and so need to define string-arrays for the contents of the Recycler layouts.
To keep things clean in my code, I'd like to keep these string-arrays out of my strings.xml files if possible.
Therefore, is it possible to use, for example, preferences.xml in the res/values folder (and provide translations in the values-?? folders) and then reference this in code?
I have tried creating preferences.xml but when I try to retrieve the arrays with
String[] prefsTitlesArray = getResources().getStringArray(R.preferences.prefs_titles);
I get an error flagged in the IDE as 'preferences' isn't recognised under R.
Do I have to stick to the standard .xml file names such as strings.xml and array.xml or is it possible to use an arbitrary file name under the values tree to keep thinsg nice and clean and obviously named?
(Note, I have looked at Is it possible to create translateable arbitrary XML resources in Android Studio? which seems to imply that arbitrary xml file names might be possible outside of the values tree, but doesn't mention how they are referenced in code (Java, in my case).
As per Mike M's comment, yes it is possible to name the XML resource files anything you want as the code reference R.????.itemName is derived from the item type not the file it comes from.
So a file called prefs.xml could contain <string name="itemName"> items and <string-array name="itemName"> items etc and they will be referenced from code as R.string.itemName and R.array.itemName.
The XML filename itself is irrelevant so long as it is saved in the correct folder within the project for value resource files.
I have a very simple application that runs an html file. I really want to change the color of the status bar, because the standard top and bottom in black is horrible for the color palette of the page shown. I have no idea about Android and I can't start learning now, but I tried to follow the answers, as in this question here at Stack Overflow: How to change the status bar color in android. However, I can't even find the styles.xml file that is indicated to put the parameters inside. I tried to create the "value" folder with the styles.xml file inside, but it only corrupted the app, as I imagined it would happen.
This is how the file tree of my app (generated by the Website to APK Builder) is seen:
What do I do to accomplish this? Please help me!
Note: I tried the edits through Android Studio.
For more details, here's the .apk: Google Drive
Change project structure to Android.
Follow below image
Now getting structure like below Image:
Here is style.xml file present under res->values
If not getting style.xml file, then Create new file res->values->New->Value Resource file
I hope this helps you
No need styles.xml file in the new Android Studio. Goto your project file view: Res>Values>Themes folder.
Open themes.xml file change actionbar.
android studio live example
You can find it in your resource directory
res/values/styles.xml
Right click on res - new - package - write the name of package as values - in the drop down of folder type, select values - ok.
The values folder is created!
Right click on values package - new - Android Resource Xml file - write name as styles in the name section - Ok.
I am developing an app with an open source code and I want to completely remove the feature of "Linked Devices" which is in settings.
I tried by deleting the string name from strings.xml file and by deleting the android:label from androidmanifest file. But it only removes the name and the feature is coming like this #2343243545 and if we click on this option the app is getting stopped.
Suggest me something to remove this completely.
Here is the link to the open source code on which I am working https://github.com/WhisperSystems/Signal-Android/tree/0a569676f7a57144374a24faef566b2ca3233290
If your intent is to remove menu item, you can find menu XML files under res/menu directory inside project files.
Look for <menu> and delete <item> or <group> tag that you do not need.
If the settings activity/fragment extends either the PreferenceActivity
or PreferenceFragment class, the drawing of the screen is driven by a file in the res/xml directory. In this case, you will need to remove the Preference (Preference, CheckboxPreference, ListPreference, EditTextPreference, etc.) defined in a file that belongs to that path. It is likely named preferences.xml.
If this is not the case/what you are looking for, please share the code that you are dealing with.
I have my strings stored in different .xml(s). Now, I need to do some translations for them and I was wondering if it is possible to open the Translation Editor for those xml. I tried but it only appears on the strings.xml
Your help will be greatly appreciated.
This is old, but I figured something out that may be helpful for anyone looking.
When you open the Translations Editor for a module, it will show all strings in the res folder, not just the "strings.xml" file. So if you have other .xml files with strings, they will be listed.
The Android Studio UI only allows the Translation Editor to be opened from the "strings.xml" file. So if you have a module that has strings files without any xml file named "strings.xml" just create a blank "strings.xml" file in that res folder and use that to open the Translations Editor - it will list all strings.
If I understand this correctly, you don't need to open separate files in translation editor.
Open your something.xml file
Alt + Enter on any item -> Override resource in other configuration
Select Locale and press the button ">>"
Choose locale needed.
This will create localization file for your something.xml file.
something.xml -> copy all innards -> paste into localization file.
If you remove all values from localization file, and than open your main strings.xml file with editor, you will find there the words from something.xml untranslated. If you won't, you will find similar values for original and new locale.
When you open in editor your strings.xml, Studio puts there all string resources from the current module, despite you put your strings in multiple files. Maybe this is not as handy, as it would be with opening files one by one, but this still good, if you just need to make sure you didn't miss any string to be translated.
Open any layout
Find this panel by image panel
Click on earth icon
Click "Edit translations"
I have pretty big translation database, almost 1k positions on every single language. And every module has its own prefix, so my string files look like this: prefix_strings_hitory.xml, prefix_strings_news.xml, prefix_strings_coutries.xml etc. Android Studio translation editor can't handle properly translations with files different than strings.xml.
That's how am I doing this:
1.In every module create empty file strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
Thanks to this you can open editor easy.
2.Now assume you want to have file named values/abc_strings_main_activity.xml, create it.
3.When we need german translation, you have to manualy make a copy of your original (default) file: values-de/abc_strings_main_activity.xml. If you let Translation Editor copy your file, it would create values-de/strings.xml instead and put your strings there.
4.Now when you use Translation Editor, it would be properly saving your string in correct files and positions.
5.When I make a copy of my file, I always use file with empty tags body, e.g.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="abc__button_1"></string>
<string name="abc__tile"></string>
<string name="abc__share"></string>
</resources>
Thanks to it, I can see empty (not translated) cells in Translation Editor
I'm using Android Studio 2.3.3
Opening the "translation editor" window I've realized that all entries from different resource file (strings.xml, otherTranslationFile.xml and so on...) are listed.
In the example I've used a prefix "c_" to better sort and recognize that specific entries
Hopefully, this is a newbie question with a quick answer...
I am attempting to add a simple preferences file in a new Android project (New -> Android XML File), but it doesn't appear to be working correctly.
There is no root element to choose from when I select the Preference type layout. If I press Finish, it doesn't do anything. See screenshot below.
Thanks,
wTs
Just create a normal xml file to the project /res/xml/ folder and add your content to the file as usual. Should work just great. Eclipse detects it as a preference file once you have added the preference-xml and saved it.
You don't need to have a root element in the selection screen. Just replace whatever eclipse generates with what you want.
try refreshing the folder that the file is supposed to be in (in your example res/xml).