开发者

Android: String value with new-line in 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 XM开发者_C百科L.

Thanks in advance


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. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜