Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: String value with new-line in XML

Tags:

android

xml

I have a menu item with a somewhat long name, be it "My very very, very extremely first android menu item inflated!".

The problem: the text is presented in a single line, and cut at the area of 'menu'.
But even if the text would fit, I'd still not want it to occupy all the space from left to right, and prefer a line break somewhere reasonable.

The question: how do I trigger a line break in the XML file (values/strings.xml)?
The line is simple:

<item android:id="@+id/MyFirstItem" android:title="My very very, very extremely first android menu item inflated!"/> 

Eclipse rejects anything starting with a '<' inside the string so that's a no-go.
Also, I don't want to leave the bounds of XML.

Thanks in advance

like image 575
Assaf Levy Avatar asked Oct 11 '22 15:10

Assaf Levy


1 Answers

Simply \n works for me.

Edit: For general XML usage you would want to use parameters like

            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"

instead of adding your own linebreaks (of course, this doesn't apply to strings.xml, but for your layout). It's time-consuming and may lead to your application looking 'wrong' on different phones / resolutions. Just in case you didn't use it already, not implying you are doing anything wrong. :)

like image 85
Codemonkey Avatar answered Nov 11 '22 10:11

Codemonkey