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>
Related
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
I am using takephoto_library for selecting multiple images.
https://github.com/crazycodeboy/TakePhoto
It is working properly but as you can see in the below screenshot, the caption is in Chinese.
I found that the view control is "com.darsh.multipleimageselect.activities" and Id of this caption is in the below
actionBar.setTitle(R.string.album_view);
Is there any way to change this string to English?
Is there any way to change this string to English?
Yes, you can change all the Strings in strings.xml
https://github.com/crazycodeboy/TakePhoto/blob/master/takephoto_library/src/main/res/values/strings.xml
Change these two chinese word to english
<string name="add">确定</string>
<string name="selected">已选</string>
In English
<string name="add">confirm</string>
<string name="selected">selected</string>
Try this .
find the strings.xml(values) and strings.xml(values-en) in the library of TakePhoto .
And change the string name to the English .
In the strings.xml(values)
string name="add">确定</string>
<string name="selected">已选</string>
<string name="limit_exceeded">最多能选 %d 张</string>
And add this to the strings.xml(values-en)
string name="add">confirm</string>
<string name="selected">selected</string>
<string name="limit_exceeded">You can choose%d at most</string>
And you can change this strings.xml(values-en) and strings.xml(values)
For internationalization, android looks in different directories for the appropriate local as determined by your selection for the phone. For instance, you should see something like this:
./explorer/src/main/res/values-uk/strings.xml
./explorer/src/main/res/values-tr/strings.xml
./explorer/src/main/res/values-ru/strings.xml
./explorer/src/main/res/values-pl/strings.xml
./explorer/src/main/res/values-de/strings.xml
./explorer/src/main/res/values-ko/strings.xml
./explorer/src/main/res/values-sv/strings.xml
...
Where the translated strings are in the values-../strings as determined by the res/values/strings.xml.
In my case, res/values/strings.xml has an entry:
<string name="createnewfolder">Create new folder</string>
which is translated in values-uk/strings.xml as
<string name="createnewfolder">Нова папка</string>
You might find Localizing with Resources useful.
In my Android app I'm using strings.xml for all texts. I have many situations where I use almost the same string,
e.g. "Name" and "Name:" - translation is the same only additional colon is difference.
Is there any other way to have these two string except creating two string items like this:
<string name="name">Name</string>
<string name="name2">Name:</string>
There is no way you can concatenate strings in the strings.xml file.
All you can do is specify the format,
<string name="name">Name</string>
<string name="string_with_colon">%s:</string>
Then pass the name programatically,
String.format(getString(R.string.string_with_colon), getString(R.string.name));
Yes, you can do so without writing any Java/Kotlin code, only XML by using this small library I created which does so at buildtime: https://github.com/LikeTheSalad/android-stem
Usage
Based on your example, you'd have to set your strings like this:
<string name="name">Name</string>
<string name="name2">${name}:</string>
And then after building your project, you'll get:
<!-- Auto generated during compilation -->
<string name="name2">Name:</string>
I need to put "TM" (trademark) character in my string.xml, how I should do that ?
<string name="snap_recipesnap_button">RecipeSnap\™</string>
I have sth like this but it doesn't work
May this help you:
<string name="snap_recipesnap_button">RecipeSnap ™</string>
i am using Eclipse 3.7.2.
I dont know why but the last line leads to an error highlightning
<string name="app_name">Test</string>
<string name="title">#string/app_name</string> <!-- works //-->
<string name="txt_text">Checkout #string/app_name this works</string> <!-- works //-->
<string name="txt_recommend">#string/app_name is not working</string> <!-- error //-->
is there a work around?
I believe you can't mix references and text in the XML. Use formatting placeholders instead.
http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
Instead of
<string name="app_name">Test</string>
<string name="txt_recommend">#string/app_name is not working</string>
this would look like
<string name="app_name">Test</string>
<string name="txt_recommend">%s is not working</string>
And in the code:
String text = String.format(res.getString(R.string.txt_recommend), res.getString(R.string.app_name));
The error is probably from the second last line rather than the last line.
<string name="txt_text">Checkout #string/app_name this works</string>
In this line you seem to be mixing text ("Checkout" and "this works" ) with a reference ("#string/app_name")
I dont think you can do that just in xml.