Android: Vertical alignment for multi line EditText (Text area) - android

I want to have 5 lines for the height of the text area. I am using the following code.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="false"
android:lines="5"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" />
The text area looks fine, but the problem is that the cursor is blinking in the middle of the text field. I want it to blink at first line, at the first character of the text field.

Use android:gravity="top"

This is similar to CommonsWare answer but with a minor tweak: android:gravity="top|start". Complete code example:
<EditText
android:id="#+id/EditText02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="top|start"
android:inputType="textMultiLine"
android:scrollHorizontally="false"
/>

U can use this Edittext....This will help you.
<EditText
android:id="#+id/EditText02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="top|left"
android:inputType="textMultiLine" />

Use this:
android:gravity="top"
or
android:gravity="top|left"

<EditText android:id="#+id/EditText02" android:layout_width="120dp"
android:layout_height="wrap_content" android:lines="5" android:layout_centerInParent="true"
android:gravity="top|left" android:inputType="textMultiLine"
android:scrollHorizontally="false" android:minWidth="10.0dip"
android:maxWidth="180dip" />
it will work

Now a day use of gravity start is best choise:
android:gravity="start"
For EditText (textarea):
<EditText
android:id="#+id/EditText02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="start"
android:inputType="textMultiLine"
/>

I think you can use layout:weight = 5 instead android:lines = 5 because when you port your app to smaller device - it does it nicely.. well, both attributes will accomplish your job..

Related

Edittext View One line

Can someone point me on how to limit the edittext as one line only?
screenshot:
my xml:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:id="#+id/textView_data2"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:maxLines="1"
android:gravity="fill_vertical" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:scrollHorizontally="false"
android:id="#+id/textView_data2"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:maxLines="1"
android:inputType="textPersonName"
android:gravity="fill_vertical" />
Just add into your XML-File android:maxLines="1"
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:id="#+id/textView_data2"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:inputType="text"
android:imeOption="actionNext"
android:gravity="fill_vertical" />
android:inputType="text"
android:imeOption="actionNext"
these two lines are the catch. you better use actionDon in imeOption
i.e.,
android:imeOption="actionDone"
use this and you are all good :)
P.S. there are multiple types of imeOption provided by android. We usually use these imeOptions for our softKeyboardInput where we need to change enter button of our keypad to anything else.
e.g., actionDone : DOne button
actionNext :Go to next editBox and etc,
These imeOption only works with inputType="text|number|..i.e. you need to specify a input type for using imeOption.
Hope it will help you :)

Set AutocompleteTextView hint in a single line with Ellipsize end

I want to set the hint of my AutocompleteTextView in a single line with extra string to be truncated with dots(...) in the end.
I am using singleLine="true", maxLines="1", ellipsize="end".
But still the hint is shown in two lines. Although The text is set to single line. But I need the hint should also need to shown in single line.
The Preview in Android Studio shows the hint in single line. But when I run it on Device it shows in 2 lines.(S5, Nexus-5, Nexus-6, J7).
I also want the imeOption should be always search. i.e. imeOptions="actionSearch" Hence I can't change it to actionNext.
Below is my XML Code:
<RelativeLayout
android:id="#+id/liLaySearchMap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingLeft="10dp"
android:background="#color/cococo"
android:paddingRight="10dp">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/five_dp"
android:background="#color/white"
android:padding="#dimen/two_dp"
android:scrollHorizontally="true"
android:drawablePadding="#dimen/two_dp"
android:singleLine="true"
android:lines="1"
android:maxLines="1"
android:ellipsize="end"
android:textSize="#dimen/twelve_sp"
android:drawableLeft="#drawable/ic_action_search"
android:inputType="text"
android:hint="A Very Long Hint Text Which Need To Be Tuncated At the End In Single Line"
android:id="#+id/edSearch"
android:imeOptions="actionSearch"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/tvCancel"
/>
<TextView
android:id="#+id/tvCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:layout_margin="#dimen/five_dp"
android:text="#string/cancel"
android:textSize="#dimen/twelve_sp"
android:textColor="#color/tw__composer_red"
android:padding="#dimen/five_dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Can Anyone Please en-curtain the issue I am facing. As I think I had used every possible solution but still the hint is not in single line.
these are screenshots on my Device and xml i tried is as follows
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/white"
android:padding="2dp"
android:scrollHorizontally="true"
android:drawablePadding="2dp"
android:singleLine="true"
android:lines="1"
android:maxLines="1"
android:ellipsize="end"
android:textSize="16sp"
android:inputType="text"
android:drawableLeft="#mipmap/ic_launcher"
android:hint="A Very Long Hint Text Which Need To Be Tuncated At the End In Single Line"
android:id="#+id/edSearch"
android:imeOptions="actionSearch"/>
try Setting android:inputType="text" on the AutoCompleteTextView it worked for me
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
android:ellipsize="end"
android:imeOptions="actionNext"
android:hint="this is to check if it's getting truncated and in single line or not"/>
Setting android:inputType="text" on the AutoCompleteTextView it worked for me, unlike android:ellipsize="end", the text did not stay with '...' on end, but it does meet expectations.
android:completionThreshold="1"

Auto capitalization of first letter of edit text not working

I am trying to add EditText with inputtype = textCapWords but it is not working for me .
I have also tried textcapsentences but it is also not working.
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/d1"
android:textCursorDrawable="#drawable/custom_cursor"
android:background="#drawable/text_field_account"
android:gravity="left|center_vertical"
android:hint="#string/Last_Name"
android:inputType="se"
android:maxWidth="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:text=""
android:maxLength="30"
android:textColor="#color/black000"
android:textColorHint="#color/text_color_hint"
android:textSize="#dimen/font_n" />
You need to use this
android:inputType="textCapSentences"
Try This
remove android:inputType
// add this it Capitalize The First Letter Of Every Word.
android:capitalize="words"
Change the input type of your Edittext.
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/d1"
android:textCursorDrawable="#drawable/custom_cursor"
android:background="#drawable/text_field_account"
android:gravity="left|center_vertical"
android:hint="#string/Last_Name"
android:inputType="textCapSentences"
android:maxWidth="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:text=""
android:maxLength="30"
android:textColor="#color/black000"
android:textColorHint="#color/text_color_hint"
android:textSize="#dimen/font_n" />
Try this it may be help to you
yourEdittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);

Android EditText not expanding when hitting enter

I have a EditText look like this in my layout xml and it's not expanding when the user hit enter
<EditText
android:layout_height="40dp"
android:layout_width="fill_parent"
android:gravity="top"
android:maxLines="10"
android:minHeight="40dp"
android:id="#+id/edSearch"
android:layout_toLeftOf="#+id/btnSearch"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:hint="City..."
/>
but when i changed android:layout_height="40dp" to android:layout_height="wrap_content" the the edittext is able to expand as the user hit enter.
how I can keep my EditText expanding while keeping this line android:layout_height="40dp"
Thanks
Try this
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="Top"
android:maxLines="10"
android:minHeight="40dp"
android:id="#+id/edSearch"
android:layout_toLeftOf="#+id/btnSearch"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:inputType="textMultiLine"
android:hint="City..."
/>
Hope this will work
I'm using following code and it's working great. to set minimum height instead of setting layout_height to 40dp set it wrap_content and set attribute of minLines to achieve this as show below in code example
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:minLines="4"
android:maxLines="10"
/>
Set property android:multiline="true".
hope this will help you.
Set android:multiline="true" along with android:gravity="left|top"

Setting EditText imeOptions to actionNext has no effect

I have a fairly complex (not really) xml layout file. One of the views is a LinearLayout (v1) with two children: an EditText(v2) and another LinearLayout(v3). The child LinearLayout in turn has an EditText(v4) and an ImageView(v5).
For EditText v2 I have imeOptions as
android:imeOptions="actionNext"
But when I run the app, the keyboard's return does not check to next and I want it to change to next. How do I fix this problem?
Also, when user clicks next, I want focus to go to EditText v4. I do I do this?
For those who really need to see some code:
<LinearLayout
android:id="#+id/do_txt_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/col6"
android:orientation="vertical"
android:visibility="gone" >
<EditText
android:id="#+id/gm_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/coldo_text"
android:hint="#string/enter_title"
android:maxLines="1"
android:imeOptions="actionNext"
android:padding="5dp"
android:textColor="pigc7"
android:textSize="ads2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/rev_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/coldo_text"
android:hint="#string/enter_msg"
android:maxLines="2"
android:padding="5dp"
android:textColor="pigc7"
android:textSize="ads2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="#drawable/colbtn_r”
android:clickable="true"
android:onClick=“clickAct”
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/abcat” />
</LinearLayout>
</LinearLayout>
Just add android:maxLines="1" & android:inputType="text" to your EditText. It will work!! :)
singleLine is deprecated. Adding an input type (eg: android:inputType="text") also worked for me.
Use android:maxLines="1" as singleLine is deprecated
android:singleLine has been deprecated, it is better to combine android:maxLines="1" with android:inputType="text". This would be the code:
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
/>
The answers given here were all very helpful, but I was still struggling to get my keyboard's "Next" to show.
Turns out that when you use Android's android:digits attribute in your XML, it prevents the android:imeOptions="actionNext" from working as expected.
The answer is actually to use the deprecated android:singleLine="True". This seems to force the IME Option to be respected.
Old, Non-Working Code
<android.support.design.widget.TextInputEditText
android:id="#+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
android:ellipsize="end"
android:hint="#string/first_name"
android:imeOptions="actionNext"
android:inputType="textCapWords"
android:maxLength="35"
android:maxLines="1" />
Working Code
<android.support.design.widget.TextInputEditText
android:id="#+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
android:ellipsize="end"
android:hint="#string/first_name"
android:imeOptions="actionNext"
android:inputType="textCapWords"
android:maxLength="35"
android:maxLines="1"
android:singleLine="true" />
I'm not a fan of using a deprecated attribute, but for now it seems to get the desired result.
single line deprecated so you add below code I think inputType must.
<EditText
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionNext" />
Finally i have got sure solution for this issue
Just add these 3 lines in your edit text and it will be working fine
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionDone"
Here you can add maxLines according to your requirement. Do not use singleLine as it is deprecated now.
Good luck!
These three lines are enough.
android:singleLine="true"
android:inputType="text"
android:imeOptions="actionNext"
android:inputType="text"
You have to specify an inputType in order for imeOptions to function.
below code is force
android:inputType="text"
Only this worked for me.
Change it:
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionNext"
on that:
android:singleLine="true"
android:inputType="text"
android:imeOptions="actionNext"
Key here is to set input type and imeOptions attributes
<EditText
android:inputType="number"
android:maxLines="1"
android:imeOptions="actionSearch" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/auth_register_re_password"
android:hint="Enter Password Again"
android:imeActionLabel="login"
android:gravity="center"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"/>
Only put in your EditText xml
android:inputType="text"
Add this following lines to in your EditText.
<Edittext
android:layout_height = "match_parent"
android:layout_widht = "match_parent"
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionSearch"
android:imeActionLabel="Search"
android:hint = "Search Here" />

Categories

Resources