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.
Related
In my RecyclerrView some items have EditText(Inside cardView).It works fine without defining InputType in EditText but when I define InputType it causes the recyclerview to scroll to position zero when EditText comes into focus(When touched on editText to enter values).
This is a default EditText that works fine
<EditText
android:id="#+id/et_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp_5"
android:layout_weight="1"
android:background="#drawable/box_blue_outline"
android:gravity="center"
android:hint="#string/name"
android:padding="#dimen/dp_5"
android:textSize="#dimen/sp_16" />
I have another EditText that accepts numbers only so I added InputType
<EditText
android:id="#+id/et_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp_5"
android:layout_weight="1"
android:background="#drawable/box_blue_outline"
android:gravity="center"
android:inputType="number"
android:hint="#string/number"
android:padding="#dimen/dp_5"
android:textSize="#dimen/sp_16" />
But clicking on this EditText to enter values, which has some position between the RecyclerView (say 7), it scrolls back to position 1.
Look like, different keyboard changes cause RecyclerView to update. It's very possible of the Window focus type. Try to change Keyboard behavior for appearing in Activity/Fragment onCreate.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Please include all View layouts, where located RecyclerView and what layouts you are binding.
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.
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 and have a hint. When I tap on the EditText, the keyboard appears, though, as I type neither the hint goes away nor my typing goes into view. It's like my input is going to /dev/null. My EditText is inside a ListView cell, if it helps. Here is my layout:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#00000000"
android:id="#+id/aboutView"
android:layout_gravity="center_horizontal|bottom"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headerFrame"
android:layout_marginTop="12dp"
android:gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:textSize="14dp"
android:layout_marginBottom="12dp"
android:hint="Tell something about yourself..." />
Why can this be?
Found the solution here: EditText in Listview loses focus when pressed on Android 4.x
I don't know the exact reason, but I wasn't the only one suffering from EditText focus problems when inside a ListView. I've added android:windowSoftInputMode="adjustPan" to my activity in manifest file and the problem went away.
I have seen many similar questions to this one but I think this still covers new ground:
1) Hint text disappears when you set gravity
2) android:ellipsize="start" fixes that so you can have centered hints and centered text
3) why does the code below still show centered hint text?
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="use this area to provide specific identification information including approximate size, vessel name and registration numbers if available"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>
is it because of fill_parent instead of wrap_content? i thought maybe it was because this hint is multiline, but i shortened it and it still appeared and was centered. those are the only differences between this and my other EditTexts that needed android:ellipsize="start" to display correctly. is it just a bug?
You need to use android:gravity="top" instead of center in order to have your hint and your text start at the top left of the box.
add this attribute to your EditText
android:ellipsize="start"
It just works
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:ellipsize="start"
android:hint="use this area to provide........"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>