I found out that android:inputType and adding "textMultiLine" and "textCapSentences" makes the input text multiline and init cap respectively, but how can we collaborate both to one edit text?
because error is shown when i put two android:inputType in a single edittext.
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView4"
android:layout_marginTop="28dp"
android:inputType="textCapSentences"
android:ems="10"
android:inputType="textMultiLine" /> // cannot add this here
i tried as per the answer but
the multiline is working but init cap is not working in both this edittext and the ones written as
android:inputType="textCapSentences"
:-(
Use like this..
android:inputType="textCapSentences|textMultiLine"
In your code
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView4"
android:layout_marginTop="28dp"
android:inputType="textCapSentences|textMultiLine"
android:ems="10"/>
inputType attribute (textCapSentence) is IME dependent.
You can achieve your requirement by adding below line:
android:inputType="textCapSentences|textMultiLine"
Still in some keyboards, it will not work. I have also used this and it is working in almost all the keyboards(Nexus, Samsung, HTC) but not in Motorola.
Related
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
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 :)
While declaring EditText in xml file, I was warned exactly as given below
No label views point to this text field with an android:labelFor="#+id/#+id/start" attribute
EditText code is
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/start"
android:hint="#string/edit_message" />
I also had no idea what this error message was trying to inform me to do!
Thankfully I found an explanation: http://thecodeiscompiling.blogspot.com/2013/12/android-labelfor-waning-fix.html
the warning is telling you the EditText field does not have a TextView that can be read to a user when accessibility is turned on, since you haven't specified one with the android:labelFor attribute.
Solution for this warning:
No label views point to this text field with an android:labelFor="#+id/#+id/editText1" attribute
When you drag and drop and Text Fields into Graphical Layout you get this above error .
The generated code looks like this:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="154dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
Solution :
add this label "android:labelFor="#+id/editText1" as shown below .
<EditText
android:id="#+id/editText1"
android:labelFor="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="154dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
Use id like following in your editText.
android:id="#+id/editText1"
And then if you want to set labelFor then use
android:labelFor="#id/editText1"
Use android:labelFor="#+id/start" instead of android:id="#+id/start".
I had an issue with setting hint in Arabic language. Please refer Alternating edit text hint not visible for Arabic language
for details. The issue was with the use of inputType in the xml. I have removed it and now a normal keypad appears onclick of the edittext field. But I want the user to enter numbers only and I want numerical keypad to appear. How to do it?
In short, the use of inputType will not display the Arabic content and if it is not used then I am getting alphabetical keypad.
Please help, thanks in advance
hope you can use this property android:numeric="integer" and please remove singleline property if you are using it.
<EditText
android:id="#+id/et_account_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:cursorVisible="true"
android:gravity="right"
android:hint="#string/hint_account_no"
android:imeOptions="actionNext"
android:numeric="integer"
android:maxLength="12"
android:textColor="#android:color/black"
android:textSize="20sp"
android:padding="#dimen/edittext_padding">
</EditText>
Use android:inputType="number" or android:inputType="phone" it should give you numeric keypad on click of edit text:
Following is the snippet from my xml, this should help:
<EditText
android:layout_gravity="start"
android:textAlignment="viewStart"
android:hint="my hint"
android:inputType="phone"
android:id="#+id/Nummm"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:textDirection="rtl"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:textColorHint="#767676"
android:backgroundTint="#android:color/transparent"
android:layout_height="fill_parent"
tools:ignore="RtlCompat" />
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