How can put into strings.xml from bakcend java android - android

I need to put value from android backend java class to the strings.xml
<resources>
<string name="test">xyz</string>
</resources>

this is impossible you can't do that

Related

Change the name of the application Android Studio

Hello I have a problem in calling the name of the application
I need to invoke the application of MainActivity name <String xxx>
<resources>
<string name="app">#layout/activity_main/#xxx</string>
</resources>
Is this possible
I do not want to use
<string name="app">name</string>
You got it wrong. It is actually the opposite way.
In strings.xml you declare:
<string name="app">Application name</string>
An in the activity you read:
getString(R.string.app);

How to include a Android values strings.xml file into another strings.xml

I need to put all codes inside values-zh/strings.xml into values-zh-rCN/strings.xml. How do i do this?
I've tried this <include layout="#values-zh/strings" /> but did not work, Intelij is telling me to declare the file first.
Assuming values-zh/strings.xml is your base string resources, you can put all your strings there, and only provide values for those you need to override in values-zh-rCN/strings.xml.
In values-zh/strings.xml:
<string name="title">default title</string>
<string name="content">default content</string>
In values-zh-rCN/strings.xml:
<string name="title">simplified title</string>
Now when you are on simplified Chinese config, content will be 'default content', and title will be 'simplified title'.

how to make #symbol in string.xml for android

I am trying to make #sancorporation in my android application. I have written strings in string.xml e.g "<"string name="cor_name">sancorporation"<"/string>, but I need something like this "<"string name="cor_name">#sancorporation"<"/string>. How to take special symbol in android?
Use ascii value of # symble is 0040 so try it
for #sancorporation
<string name="mytest">#sancorporation</string>
or
<string name="mytest">\u0040 sancorporation</string>
Maybe this will help
<string name="specialChar"> "#" </string>
You can also try this
<string name="specialChar"> \# </string>
Edit:
Now I notice that you want to write #sanCorporation.
so you can use this in string.xml file:
<string name="corp"> "#sanCorp" </string>

Keeps String values separated in Android Resources

As you know you can write whatever resource you need inside res/values.
I made an xml file for each gui/activity I'm using. Here's an example:
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">This is home!</string>
<string name="app_name">Hattrick4Manager</string>
<string name="oauth_button">Authorize me!</string>
<string name="download_button">Syncronize</string>
<string name="oauth_name">Authorization</string>
</resources>
update-ui.xml
<resources>
<string name="inizio_download">Update Started...</string>
<string name="fine_download">Update Completed...</string>
<string name="update_title">Update</string>
<string name="update_done">Done</string>
<string name="update_inizio_club">Club...</string>
<string name="update_inizio_arena">Arena...</string>
<string name="update_inizio_fan">Fans...</string>
<string name="update_inizio_matches">Matches...</string>
<string name="update_inizio_league">League...</string>
<string name="update_inizio_leaguefix">League Fixtures...</string>
<string name="update_inizio_economy">Economy...</string>
<string name="update_inizio_players">Players...</string>
</resources>
When I use this in the code I have to recall them like:
R.string.update_done
or
R.string.hello
my problem is that like this I have basically to add the prefix for every GUI I make. I would prefer doing something like:
R.string.update-ui.done
Is it possible?
You can create as many resource files as you want, but you can not perform the nested name referencing based on the filename: the Android aapt tool doesn't support arbitrary nested objects on the generated R object.
You might be able to do stuff like this in update-ui.xml:
<resources>
<string name="update_ui_inizio_download">Update Started...</string>
<string name="update_ui_fine_download">Update Completed...</string>
</resources>
and then use
R.string.update_ui_inizio_download
to reference the contents of the file

Can one combine android resource strings into new strings?

Android allows to create aliases of resource strings like:
<resources>
<string name="foo">somestring</string>
<string name="bar">#string/foo</string>
</resources>
by which the resource "bar" becomes an alias for the resource named "foo".
What I would for my app is a possibility to combine an existing resource prefix with different suffixes, i.e. to extend it like:
<resources>
<string name="foo">foo</string>
<string name="bar">#string/foo+bar</string>
<string name="else">#string/foo+else</string>
</resources>
where the resource "bar" would yield the string "foobar". Its clear that '+' doesn't work here but is there some other option to achieve such a string concatenation, so that one could define a bunch of string resources that have a common prefix?
I realize of course that I could do such resource string concatenation at runtime but defining them statically in the resources would seem so much more elegant and simpler.
Michael
No, it's not possible.
You can just use <string name="bar">This is my %s</string>
and then use String.format() in your app to fill in the variable with for example
getResources().getString(R.string.foo);
I know it's late, but anyways now you can do so by using this library I've created: https://github.com/LikeTheSalad/android-stem
It will concat all of the strings you want to at build time and will generate new strings that you can use anywhere in your project as with any other manually added string.
For your case, you'd have to define your strings like so:
<resources>
<string name="foo">foo</string>
<string name="bar">${foo} bar</string>
<string name="else">${foo} else</string>
</resources>
And then, after building your project, you'll get:
<!-- Auto generated during compilation -->
<resources>
<string name="bar">foo bar</string>
<string name="else">foo else</string>
</resources>
These auto generated strings will keep themselves updated for any changes that you make to your templates and values. They also work with localized and flavor strings. More info on the repo's page.

Categories

Resources