Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple lines on a button

List item

I want to create a button with one image and more than 2 lines of text. Is it possible in XML? (eclipse)

I`m trying with this code:

    android:id="@+id/itm1"
    android:text="item1"
    android:typeface="sans"
    android:textSize="20sp"
    android:textColor="#ffffff"
    android:width="250dip" 
    android:height="150dp"
    android:drawableLeft="@drawable/image1"
    android:background="@android:color/transparent" 
    android:layout_marginLeft="80dp"/>
like image 839
Peter Avatar asked Aug 23 '26 02:08

Peter


2 Answers

To insert multiple lines in a button, you might use the string.xml to insert the end of line.

1 Create a new variable with the character endOfLine "\n" in the res/values/strings.xml. For example:

<string name="multiplelines">Line1 \n Line2</string>

2 Refer it in the layout file. For example, for a button:

<Button
    android:id="@+id/start"
    android:text="@string/multiplelines"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent">
</Button>

Source: http://www.jiahaoliuliu.com/2011/10/android-multiple-lines-for-layout.html

like image 112
jiahao Avatar answered Aug 25 '26 15:08

jiahao


It is a little late, but you can also specify number of lines in the Button itself:

<Button
    android:id="@+id/start"
    android:lines="2">

</Button>
like image 43
longwalker Avatar answered Aug 25 '26 17:08

longwalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!