Change the name of the application Android Studio - android

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);

Related

How can put into strings.xml from bakcend java 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

Can I embed a string resource into another string resource?

The Code A is a string resource, I hope to merge two string resources into one, just like Code B, can I do it in Android Studio 3.01?
Now I have upgraded to kotlin.
Code A
<string name="app_name">Backup Settings</string>
<string name="FeedbackEmailSubject">Report bug and suggestion about Backup Settings</string>
Code B
<string name="app_name">Backup Settings</string>
<string name="FeedbackEmailSubject">Report bug and suggestion about <string name="app_name"/></string>
I don't think there is such a way. Best way right now is below.
<string name="app_name">Backup Settings</string>
<string name="FeedbackEmailSubject">Report bug and suggestion about %1$s</string>
Observe %1$s in second string and in Code you do
getString(R.string.FeedbackEmailSubject,getString(R.string.app_name))
Which should give you out put like
Report bug and suggestion about Backup Settings

Hebrew language not showing - Android

I have created 2 string files one the default under res/values/strings.xml and the other under res/values-he/strings.xml. I am opening my app, while the os is configured to be in Hebrew, but still I see the values of the default strings which are in English. Is there any thing more to do?
Note: in the eclipse graphical layout editor I can choose Hebrew and see that it works fine.
Here is some of my default strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyApp</string>
<string name="title_activity_splash">MyApp</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_login">Login</string>
<string name="email">Email</string>
<string name="password">Password</string>
<string name="forgot_password">Forgot password?</string>
<string name="sign_up">Sign up</string>
<string name="login">Login</string>
.
.
.
and here is all (for now) my hebrew strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">הגדרות</string>
<string name="hello_world">שלום עולם</string>
<string name="email">דואל</string>
<string name="password">סיסמא</string>
<string name="forgot_password">שכחת סיסמא</string>
<string name="sign_up">רישום</string>
<string name="login">התחברות</string>
</resources>
Here it in eclipse:
here it on the device (device os in hebrew):
OK, you correctly have:
res/values/strings.xml
and
res/values-he/strings.xml
With the correct structure, be also sure that the strings have the very same names in each strings.xml file, or the trick won't work.
The missing strings in a translation file won't be translated and the default strings (from res/values/strings.xml) will be used instead.
For hebrew, in particular, on some devices values-he is recognized. in some others it's values-iw.
So, make a copy of values-he and name it values-iw. Keep both in your structure.
What solved the problem for me was to use the folder values-iw.

Android strings.xml not in R.id

I am unable to see my values in my strings.xml
When I try to see it in R.id it doesnt exist
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">BPhonelist</string>
<string name="action_add_contact">Add Contact</string>
<string name="action_phone_contact">Phone Contact</string>
<string name="action_work_contact">Phone Work Contact</string>
<string name="action_home_contact">Phone Home Contact</string>
<string name="action_email_contact">Email Contact</string>
<string name="hello_world">Hello world!</string>
<string name="detail_toast_add">Contact Added</string>
</resources>
Please if you know how I can get access it tell me.
When I try to see it in R.id it doesnt exist
that's because these are in your strings.xml. They aren't id resources. Try accessing with something like
String someString = getResources().getString(R.string.app_name);
This is assuming you are already in the Activity Context. If not, you will need to have a Context before getResources()
R.id.* values will be generated from layout files using android:id="+#id\myid"
You can reference your strings via the R.string. prefix.

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

Categories

Resources