This is what I want to do, in standard way.
<string name="foo">foo</string>
<string name="foo_bar">foo bar</string>
Can I rewrite like below?
<string name="foo">foo</string>
<string name="foo_bar">#string/foo bar</string>
I know this is not in schema, however, it is OK like below,
<string name="foo">foo</string>
<string name="altfoo">#string/foo</string>
Why!?
This
<string name="foo">foo</string>
<string name="foo_bar">#string/foo bar</string>
wrong coz there is no resource with the name foo bar
The above would be right if you had
<string name="foo bar">foo and bar</string>
<string name="foo_bar">#string/foo bar</string>
This
<string name="foo">foo</string>
<string name="altfoo">#string/foo</string>
is right coz there is a resource with name foo and you are referencing the same
You may want to check
Concatenate Strings in the strings.xml file for Android
Related
I have been struggling to understand how to change the font family of the values/Strings.xml directory. Is there an easy way to change the font? I have added my desired font to the assets folder, but my titles are in the Strings.xml inside the values directory like this:
<resources>
<string name="app_name">FarrApp</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_search_result">Search results</string>
<string name="title_activity_login">MyApp</string>
<string name="title_activity_Calendar">Calendar</string>
<string name="title_vision">Find local events near you</string>
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_password">Keyword</string>
<string name="action_sign_in">Register</string>
<string name="action_sign_in_short">Sign in</string>
<string name="action_forgot_password">Forgot password?</string>
<string name="action_forgot_submit">Reset password</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
I am not really good at designing my app and do not have too much experience with design layouts. Any help will be greatly appreciated.
You will need to reference the font in your code, then apply it to your views:
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/DroidSans.ttf");
TextView tv = (TextView) findViewById(R.id.textView);
tv.setTypeface(tf);
Or you can do it from the xml with the attribute android:typeface.
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.
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.
I am doing a project, it is going to finish but I am facing a problem to release the project. Right now, the context of the project is in English. But the requirement is like, according to the country location the context will be changed e.g Japanese, Spanish, Chinese etc. So my concern question is how to do that?
Foe English I have written like:
<string name="bookedittext">EDIT</string>
<string name="button_delete">Delete</string>
<string name="button_delete_cancel">Cancel</string>
<string name="button_back">Back</string>
<string name="progress_deleting">Deleting...</string>
<string name="share_message_conf_delete">Do you want to delete?</string>
<string name="share_message_conf_delete_all">Do you want to delete all?</string>
<string name="TEXT_SHARE_VIA">Share Via</string>
<string name="TEXT_CONTENT">Image content</string>
<string name="TEXT_SELECT_APPLICATION">Select an Application</string>
<string name="TEXT_MORE_OPTIONS">More Options</string>
<string name="TEXT_FACEBOOK">Facebook</string>
<string name="TEXT_KAKAO_TALK">Kakao Talk</string>
<string name="TEXT_SKYPE">Skype</string>
<string name="TEXT_KIK">Kik Messanger</string>
<string name="TEXT_FRING">Fring Messenger</string>
<string name="TEXT_TWITTER">Twitter</string>
<string name="TEXT_YAHOO">Yahoo Messenger</string>
<string name="TEXT_USE_FOR_DEFAULT">Use this by default action</string>
<string name="TEXT_USE_FOR_BACK">Back</string>
Please help me how to convert these to Japanese?
You can have multiple resouce files, for different locales.
Read
http://developer.android.com/guide/topics/resources/localization.html
and
http://developer.android.com/reference/java/util/Locale.html.
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