I want to have an EditText which is multi Line and First Letter of a Sentence to be capital. I'm using:
<EditText
android:id="#+id/editText2"
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="32dp"
android:layout_marginTop="67dp"
android:background="#ddebed"
android:ems="10"
android:inputType="textMultiLine|textCapSentences"
android:singleLine="false"
android:text="#string/same" />
I can acheive both: MultiLine and CapSentences.
But, When I press 'Space key' after a word, It goes to a new line.
How do I prevent it?
The android:text="#string/same" refers to <string name="same">\n \n \n Regards: Principal</string>
So, The problem is being caused by \n's.
I want to have an EditText which has some already typed text in next Line, And Allow User to enter some text in First 'n' lines.
Use android:maxLines="1" and android:inputType="text"
Your Edittext should look like below.
<EditText
android:id="#+id/editText2"
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="32dp"
android:layout_marginTop="67dp"
android:background="#ddebed"
android:ems="10"
android:maxLines="1"
android:inputType="text|textCapSentences"
android:text="#string/same" />
OR
If you are looking for multilines you can edit your edittext as
android:inputType="text|textMultiLine|textCapSentences"
Similarly you can increase android:maxLines="2"
I have checked it out. You can use above code with some below modifications.
EditText editText = (EditText)findViewById(R.id.editText2);
editText.setSelection(0);
It will move your cursor to position 0. Also try to increase maxlines value. I have checked it my end and it's working fine.
Try using this tag in xml.
android:singleLine="true"
You can Add Two Hidden Spaces Before \n's.
To add a Hidden space: Alt + 0160 (Numpad keys).
So, When User is typing something, The Hidden Spaces will keep moving and UserText won't be able to reach to \n.
Related
I am making an Android app and want the done key to show up on the keyboard when the user is typing into the keyboard.
This is the XML code for the EditText:
<EditText
android:id="#+id/answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:layout_marginBottom="113dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:imeOptions="actionDone"
/>
I thought that adding the android:imeOptions="actionsDone would have the done button appear, but instead the enter button is there and when it is pressed, a new line is created in the EditText. What is the issue?
You will not get done by adding imeOptions.
Add the below attribute to your EditText:
android:singleLine="true"
This will make your EditText a single line and you will see the Done button if that is the only EditText or last EditText. If there are multiple EditText items, then you will see Next button.
I have an EditText defined in my half screen RelativeLayout. and it appears perfectly. However, if I start typing typing more than 1 line in my EditText, it makes my entire entire window expand. I want the EditText to roll up and only show the currently typing line? Like in Facebook Messager, I want the EditText to keep scrolling itself as the user types new lines? HEre is how I implemented the EditText
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/button1"
android:ems="10"
android:focusable="true"
android:inputType="textMultiLine" />
Just set
android:maxLines="1"
This makes the TextView be at most this many lines tall.
I am having a (?simple?) problem with EditText. Whenever I type in it, the text stays in the same line even when I get to the edge of the screen instead of creating a new line. I sure I remember it doing this by default before, but I can't seem to get it to work know...
<EditText
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/hint"
android:inputType="textCapSentences" />
EDIT: The problem is because a have android:inputType. Is there any way to have the input type with the multiple lines?
You can set more than one property on the input type by separating the flags with the pipe "|" character. Try a setting like:
android:inputType="textCapSentences|textMultiLine"
Complete Code:
<EditText
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/hint"
android:lines="3"
android:inputType="textCapSentences|textMultiLine" />
I want to make a multi line edit text but the problem is that whenever i enter new line height of edit text increases. how to fix its height. My code is
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
To fix the size of editText you can use
android:singleLine="true"
but it can limit your editText line to 1 .
if you want more lines in editText then use the following property.
Use android:lines="3" .
Use android:lines="2" for fixing multilines and for fixing single line use android:singleLine="true"
for example use like this as shown for multilines
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
for example use like this as shown for single line
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
try this;
android:inputType="textMultiLine"
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
As singleline is now deprecated use inputType:multiline and set the number of lines you want with lines tag
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
I had a similar requirement but ended up not changing the size of the box. i.e it grows as text is typed into it but stops short of blocking the other widgets in view. I read this post during my quest and had found a solution. Decided to post it back here. Restricting size to a value may possibly have different effects on different screens. So I think it is better to let it be.
The thing is to put the edit text inside a linearlayout with the rest of the widgets. The code and snapshot are here
Multi line edit box with ok cancel buttons
I want to have a EditText view that is five lines high. I want it five lines high for visual appeal reasons only (so that it does not appear cramped). The code below does not work, the EditText appears only one line high.
I have tried multilinetext and it works visually, however I want to abandon it as I want the virtual keyboard to say "Next" (rather than have the enter key that is automatically provided with multiline text)
How can I make my EditText box bigger? Alternatively, how can I use the imeOption "actionNext" with multiline text?
This code does not work...
<EditText
android:id="#+id/etEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="text"
android:lines="5" //this has no effect!
android:imeOptions="actionNext"
style="#style/dialogInput" />
Change:
android:inputType="text"
to:
android:inputType="textMultiLine"
Works for me!
<EditText
android:id="#+id/etEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="text"
android:lines="5" //this has no effect!
android:imeOptions="actionNext"
style="#style/dialogInput"
android:singleLine="false" />
android:singleLine="false" will make editText to support multiple lines
On the other hand, you can try to use a line-break on text string to display, this is the tip: http://xjaphx.wordpress.com/2011/07/15/set-line-break-in-textview/
and of course, you must set:
android:singleLine="false"
Change:
android:inputType="text"
To:
android:inputType="textImeMultiLine"
If that doesn't work then change:
android:inputType="text"
To:
android:inputType="textMultiLine"
and delete:
android:imeOptions="actionNext"
style="#style/dialogInput"