How to make two break ines in android string resource? - android

I am trying to leave an empty line in a string resource
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">"Hello\nWorld!"</string>
</resources>
The above just puts "world" in the next line, but I need to leave an empty line. any help or sugestion would be great.

try
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">"Hello\n\nWorld!"</string>
</resources>

Related

Can I use another .xml file in values/strings.xml file?

I have a question about values/strings.xml
I'd like to use strings.xml, but use another strings.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
<string name="test">veeeeeeeeeeeeeeeeeeeeeeeery long script(about 1000characters)</string>
</resources>
like this, when I want to manage veeeeery long script by another xml file.
Then can I use another .xml file in values/strings.xml file?
for example like..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
<string name="test"> #values/script.xml </string>
</resources>
Thank you for reading my question.
Have a nice day :)
Yes, you just need to use #string instead of #values

Android Strings with apostrophe

How to add apostrophe in Android String Resource File?
Hi!,
I'm trying to add apostrophe (') in android strings
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Stack's Answers</string>
</resources>
Try:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Stack\'s Answers</string>
</resources>
You have to escape the XML with a \ before the apostrophe because it is a character that has a special meaning in Android's XML.
Try this way..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Stack\'s Answers</string>
</resources>

Which one is correct about bools.xml?

I find there are two ways to define bool var in bools.xml, which one is correct? Thanks!
----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="screen_small">true</bool>
<bool name="adjust_view_bounds">true</bool>
</resources>
-------------------------------------------
----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="bool" name="api11">false</item>
</resources>
----------------------------------------
Using <bool> make code shorter and cleaner, but both syntax is correct and work.
Correct syntax for boolean would be :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool
name="bool_name"
>[true | false]</bool>
</resources>
See : http://developer.android.com/guide/topics/resources/more-resources.html

change a string in my xml code non programatically

Hello I am wondering if there is a way to change a string value in my xml code without touching the .java file
e.g.
in case i have in the strings.xml
<string name="title"> This is my title</string>
If I can change inside my main.xml file
The string to have the value: This is my title
meaning to have the third word of my string on bold
Thank you
In your strings.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title"> This is <b>my</b> title</string>
</resources>

XML Code Not Working

I am a beginner at coding Android Apps.
Here is my XML code under arrays.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="difficulty">
<item>"#string/easy_label"</item>
<item>"#string/medium_label"</item>
<item>"#string/hard_label"</item>
</array>
</resources>
"#string/easy_label" and the other labels are not highlighted a color. I'm assuming my program won't run because there is a problem here. Does anyone know how I can re-adjust this to make my Android program work?
On a side note: I have easy_label, medium_label, and hard_label all declared in strings.xml, so I don't think the reference to strings.xml is the problem.
What if you do it without double quotes:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="difficulty">
<item>#string/easy_label</item>
<item>#string/medium_label</item>
<item>#string/hard_label</item>
</array>
</resources>

Categories

Resources