Set AutocompleteTextView hint in a single line with Ellipsize end - android

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"

Related

Comments section like instagram for edit text

I am trying to make the comments section the same as Instagram for edit text. My requirement is to show send as imeOptions with multiline typing and expanding the edit text.
This is what I tried, it starts typing in the next line but the edit text not expanding.
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/etComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:hint="Add comment here..."
android:imeOptions="actionSend"
android:inputType="textCapSentences"
android:lineSpacingExtra="2dp"
android:lineSpacingMultiplier="1.2"
android:maxHeight="#dimen/margin_100"
android:maxLength="200"
android:maxLines="10"
android:singleLine="false"
android:textColor="#color/white"
android:textColorHint="#color/hint_color"
android:textSize="14sp" />
Your XML is nearby correct. Please add inputType = 'text' as well.
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/etComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:hint="Add comment here..."
android:inputType="text|textCapSentences"
android:imeOptions="actionSend"
android:lineSpacingExtra="2dp"
android:lineSpacingMultiplier="1.2"
android:maxHeight="#dimen/margin_100"
android:maxLength="200"
android:singleLine="false"
android:textColor="#color/white"
android:textColorHint="#color/hint_color"
android:textSize="14sp" />
Also, in activity class
etComment.setHorizontallyScrolling(false);
etComment.setMaxLines(Integer.MAX_VALUE);
Let me know, if that works.
you need to catch text change and change the height manually according the number of lines entered by user for expanding or sharing

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 :)

EditText won't write into single line

I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.
I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that makes EditText completely unusable.
This is EditText XML:
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp" />
I think this will work for you. Let me know if it works.
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
This post might help you as well.
For single line in EditText, you just need to set two properties:
android:inputType="text"
android:maxLines="1"
Adding this line in the edittext make scrollable singleline text.
android:inputType="textShortMessage"
**This example helps you to create multiline EditText in Android.**
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
>
<!--
android:scrollbars="vertical"
It will display a vertical scrollbar if the EditText text exceed
3 lines (android:maxLines).
-->
<EditText
android:id="#+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:hint="Multiline EditText by XML layout"
android:fontFamily="sans-serif-condensed"
android:background="#d3d7b6"
android:minLines="2"
android:maxLines="3"
android:scrollbars="vertical"
android:inputType="textMultiLine"
/>
<EditText
android:id="#+id/et2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:hint="Multiline EditText programmatically"
android:background="#d4d7a5"
android:layout_below="#+id/et"
/>
</RelativeLayout>

edit Text is not accepting numeric Keyboard in expendable ListVIew

here is my code in xml
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="0.00"
android:inputType="number|numberDecimal"
android:layout_marginRight="5dp"
android:textSize="16dp"
android:id="#+id/et_childinput1"
android:background="#ffffff"
android:imeOptions="actionDone"/>
i also tried android:numeric="decimal" which is diffracted how can i do this.
i come to know that
android:numeric
android:phoneNumber
android:inputMethod
android:capitalize
android:autoText
are replaced by android:inputType
the code above work for me in Edit Text but when it come inside expendable list-view child ,the issue arise there the keyboard arise but again full keyboard is replaced by numeric in a instance
any help will be appreciated
<EditText
android:id="#+id/phoneNoRegEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:ems="15"
android:hint="Phone"
android:inputType="phone"
android:maxLength="10"
android:singleLine="true"
android:textColorHint="#color/blue_home"/>
It may help you
If you want only Numbers then it may help you
<EditText
android:id="#+id/phoneNoRegEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:ems="15"
android:hint="Phone"
android:inputType="number"
android:digits="01234567989"
android:maxLength="10"
android:singleLine="true"
android:textColorHint="#color/blue_home"/>

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