Edittext View One line - android

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

Related

EditText not working in text android

I'm facing an issue regarding EditText.
EditText is not working in couple of android devices when inputType:Text / TextMultiline/ TextPersonName.
but when you use inputType:Number
It works in all devices
what is the issue?
<EditText
android:id="#+id/quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Quantity 1Kg Meat etc"
android:focusableInTouchMode="true"
android:textIsSelectable="true"
android:clickable="true"
android:inputType="text"
android:textSize="14sp"
android:textColor="#android:color/black"
android:textColorHint="#android:color/black"
android:layout_below="#+id/line1"
android:layout_alignParentStart="true" />
Firstly it didn't show the keyboard
then i use this
android:windowSoftInputMode="stateVisible|adjustResize"
after this i can't edit the text fields
if inputType:number then it works
One thing i want to add more is i'm using this in custom ListView
I think problem with android:textIsSelectable="true" try to remove and check
<EditText
android:id="#+id/quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Quantity 1Kg Meat etc"
android:focusableInTouchMode="true"
android:clickable="true"
android:inputType="text"
android:textSize="14sp"
android:textColor="#android:color/black"
android:textColorHint="#android:color/black"
android:layout_below="#+id/line1"
android:layout_alignParentStart="true" />
android:inputType="textNoSuggestions|text"
android:focusable="true"
Working solution
If mobile text prediction is on then use above inputType to edit textfields

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"

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"/>

EditText textAllCaps not working with textIsSelectable

I have a TextView in my layout:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="Hello"
/>
textAllCaps works good, no problem. But when I try to make text selectable by adding textIsSelectable
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textIsSelectable="true"
android:text="Hello"
/>
textAllCaps not working. It seems like these two attributes can't work together properly. Have you any suggestions why it happens and how to make text both all caps and selectable (I'm interested in a most clear way, not setting text change listener and capitalizing text manually). I'll be appreciate for any suggestions, thank you.
Can you try this in Activity :
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
I found one solution. It's to use AppCompatTextView and app:textAllCaps:
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:textAllCaps="true"
android:textIsSelectable="true"
android:text="Hello"
/>
I'm not sure this is the best solution (AppCompatTextView docs tells to use this component only when creating custom components), but it works.
You can set inputType property as "textCapCharacters" for Uppercase keyboard as default
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapCharacters"
/>
use like this
<android.support.design.widget.TextInputLayout
android:id="#+id/input_postcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapCharacters" //use this line dont forgot
android:textColorHint="#color/white"
app:hintTextAppearance="#style/TextAppearance.App.TextInputLayout">
<EditText
android:id="#+id/et_postcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:backgroundTint="#color/white"
android:gravity="center_vertical"
android:hint="Post code "
android:inputType="text" //dont use hereinputtype
android:imeOptions="actionNext"
android:maxLength="4"
android:padding="10dp"
android:textAllCaps="true"
android:singleLine="true"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="15sp" />
</android.support.design.widget.TextInputLayout>

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