My button's layout_width set to match_parent.
In order to display multi lines on the button, I tried:
insert '\n' into the text on button
set Singleline false set Maxlines to 2 or 3
convert html from Html.fromHtml
Nothing worked. '\n' showed up as a small square on the button while showing single line of text.
Does anybody have any idea why this is happening and how I can fix this?
UPDATE: I just found out I was using custom button that has its own text drawing. That's the reason. Sorry for the confusion. I just punished myself by banging my head.
If you're trying to add a new line in a layout XML file:
Use
(new line)
android:text="Hi
Hello"
If you're trying to add a new line in code, just use '\n', same as in any other text.
If you can't see the second line, it may be that your Button doesn't have enough height. IE, in my case, the layout containing the button had a fixed height that just happened to make my button perfectly display one line of text.
I just tried and it worked:
1) Define in ../res/values/strings.xml:
<string name="multilines">Line1Line1\nLine2Line2</string>
2) Refer it in the layout file:
<Button
android:id="#+id/btn_multilines"
android:text="#string/multilines"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</Button>
In case you want to do that programmaticaly you can use System.getProperty("line.separator") in the string to change lines.
Like this:
String mybuttontext=line1+System.getProperty("line.separator")+line2;
and then set this String as buttons text.
Related
I'm using Drafty formatting for displaying Quoted messages
If I write long message instead of 'quoted text' (in the picture), it doesn't display as single line and with dots.
How can I display it like this:
Can you show me the XML file of the design?
for now i can assume that you have set constraints of your Quoted message with above title.
-> you can remove the constraint and set it free to expand its width, hope it will help you.
Thank you.
In the layout definition of TextView,
<TextView
... Rest of your stuff
android:lines="1" // or 2 (if the name and message are part of the same view)
android:ellipsize="end"/>
I have a textview with fixed height. I want to set a long text, but text comes at the last line getting cut by half, I want to avoid it and want to show a continuation symbol. I am giving an image here, I wan to achieve it like in the image.
Use the ellipsize attribute of TextView. By setting :
<TextView
....
android:ellipsize="end">
</TextView>
if the text is longer than your TextView you will have dots(...) at the end of the TextView.
Two line of string only possible to do like this. set ellipsize = end in text view properties.
you should use \n and special symbols from google code.
I am having a strange issue, the words are cutting inside EDITTEXT i have set an image as background. Plz help me... for example here ffsds, is being cut, I want it to shift to bit right so that it doesnt get cut.
Increase paddingLeft value of edit text.
...
android:paddingLeft="100dp"
...
in xml layout.
Increasing the left padding is the easy solution. But if this smiley image is always on the left of the edittext, you can set the image by using the attribute android:drawableLeft on the edittext.
hi all i have a lil problem in android edit text
actually i made an app in which i m using two text fields for user name and password and set EditText size manually like in 200dip format. now when there is no text in the Edit Text it is in perfect size like in the image below but when we start typing text and the text exceeds the size of editText Field then it Expand downwards like in second image below.
What I want is that when text exceeds the size of EditText, it should not Change its size. please help
android:singleLine="true" should work.
add this property for EditText and check...
android:singleLine="true"
You have to do your ExitText to be single line. You can use android:singleLine but it is deprecated and it's replaced by android:inputType. Use android:inputType=text for single line and android:inputType=textMultiline for multiline
android:maxLines="1"
Another property...
I have an edit text and I'd like to put the following constrains (in the XML code if possible):
Disable all the capital Letters (the inverse of android:capitalize or the same fonction than toLowerCase())
Block to EditText to 1 line max. (for instance avoid that when I press enter the editText
get bigger to create a new line)
In fact , my editText is a Search Field (but in my case I don't want to use the special Search Widget).
Thanks
To make the edittext single line add this to its tag:
android:singleLine="true"
Also android:capitalize is depreciated and the following should be used instead
android:inputType="textCapCharacters"
However there seems to be no matching lowercase inputType, so you may have to implement it manually using a setOnKeyListener.
use android:lines="1" in the android xml page and then see the layout.