Android Ice Cream Sandwich Edittext: Disabling Spell Check and Word Wrap - android

Whilst testing on the Android Emulator running Android 4.0 (Ice Cream Sandwich), I have noticed that the Edittext does some quite strange things.
Firstly, it underlines every word identified as "misspelt" in red. How do I disable this?
Secondly, although in the layout XML I have specified android:scrollHorizontally="true" word-wrap is enabled: how do I disable this as well? Here is the Layout XML code for the Edittext:
<EditText
android:id="#+id/editor"
android:layout_width="40dp"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_below="#+id/toolbar"
android:layout_toRightOf="#+id/toolbarleft"
android:paddingBottom="0dp"
android:paddingRight="0dp"
android:scrollHorizontally="true"
android:text=""
android:inputType="textMultiLine" >
<requestFocus />
</Edittext>
Here is an example of the spell checker I need to disable:
(source: abstract-thoughts.com)
Thanks very much!

Disabling Spell-Checking
In order to get rid of spell checking you must specify the EditText's InputType in the XML as the following:
android:inputType="textNoSuggestions"
However, my EditText needed also to be multiline, so I have added the following line to the EditText's XML:
android:inputType="textMultiLine|textNoSuggestions"
Disabling Word-Wrap
As noted, the XML attribute android:scrollHorizontally="true" does not work. However, strangely, if it is done through Java it does work. Here is the necessary code to achieve no word wrapping:
mEditText.setHorizontallyScrolling(true);

Disabling Spell-Checking in EditText.
In Android 4.0+ sometimes I get a red underline in my Textview so i add the property ...
android:inputType="textNoSuggestions"
textNoSuggestions: to indicate that the IME should not show any
dictionary-based word suggestions.
Here is a list of possible properties that we can define in :
android:inputType
Disabling Word-Wrap
remember that the property android:scrollHorizontally="true" doesn't work, so this is the solution:
mEditText.setHorizontallyScrolling(true);

In your Java class you can add to the Edittext object...
wire1type = (EditText)findViewById(R.id.wire1type);
wire1type.setInputType( ~(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) );
This clears out the autocorrect flag and will work in API 4.

android:inputType="textMultiLine|textPhonetic"
removed all red underlines for me.
android:inputType="textMultiLine|textNoSuggestions"
produces compilation error.
I use Android API 1.6.

Disabling the spell checker for general text input via code:
mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

remove android:inputType="" and all should be well.

To disable line wrapping you have to wrap (pun not intended) your EditText with an HorizontalScrollView and set your layout_width to match_parent.

Related

Android: add DONE key to soft keyboard deprecated attribute

I am trying to add a DONE key to the soft keyboard so that it will hide when the user is done adding text to an EditText.
The thing is that, from other answers here, I saw that adding the following to the XML file will do the thing:
android:imeOptions="actionDone"
android:singleLine="true"
It actually WORKS fine, and the DONE key is showed....however, Android Studio is complaining, telling that android:singleLine="true" is deprecated, use maxLines = 1.
Well, if I change android:singleLine="true" with maxLines = 1 it DOES NOT WORK and the DONE key is not showed.
Am I missing something here?? (Android Studio 2.3.3 I am using)
android:singleLine is Deprecated .You should use maxLines with inputType .
android:imeOptions="actionDone"
android:maxLines="1"
android:inputType="text"

EditText added is not a TextInputEditText. Please switch to using that class instead

I'm using an EditText inside a TextInputLayout, but after upgrading the support library to 23.2.0, I get this warning in the logcat, What's the difference between a regular EditText and a TextInputEditText? I can't seem to find any documentation for it.
I was wondering this too, Daniel Wilson gathered the documentation, but to the untrained eye it doesn't mean much. Here's what it's all about: "extract mode" is referring to the type of view that's shown when the space is too small, for example landscape on a phone. I'm using Galaxy S4 with Google Keyboard as input method editor (IME).
Landscape UI without visible IME
Based on the focus (on Description) you can see TextInputLayout in action pushing the hint outside the editor. Nothing special here, this is what TextInputLayout is supposed to do.
Landscape UI editing empty Name field
Editing the Name you can see that the IME doesn't give you a hint of what you're editing.
Landscape UI editing empty Description field
Editing the Description you can see that the IME gives you a hint of what you're editing.
Layout XMLs
The difference between the two fields is their type EditText VS TextInputEditText. The important thing here is that TextInputLayout has the android:hint and not the wrapped EditText, this is the case when TextInputEditText's few lines of Java code makes a big difference.
Name field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
>
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>
Description field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Description"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="4"
android:scrollbars="vertical"
/>
</android.support.design.widget.TextInputLayout>
There is no documentation for it, but the class is a regular EditText with a single extra feature:
Using this class allows us to display a hint in the IME when in 'extract' mode.
Specifically it sets the EditorInfo.hintText. You'll notice in the TextInputLayout class you can specify the hint and it's appearance rather than as part of the child EditText widget.
If you need to do that, you should use a TextInputEditText so it pays attention to the hint info you specified in the TextInputLayout.
They are essentially the same thing, but I think the TextInputEditText has more features and possibly attributes. I changed to the TextInputEditText and everything worked and looked as it did before with the standard EditText.
The only difference is that when your device is in landscape mode, TextInputEditText will show the hint, EditText won't.
I had this problem and just deleted this line in my xml file:
android: fitsSystemWindows = "true"
and the error disappeared.

Android EditText Multiline does not work as it should

I'm pretty desperate about this feature.
I tried pretty much everything there is to find to made these EditTexts multiline enabled,
but they just keep going on a single line scrolling the entire EditText with it.
How hard can it be to stop at the end of the border of the EditText and move to the next line?
I have this activity with an EditText and 2 buttons. One of these buttons adds a predetermined line of text to the EditText. The other puts the EditText's text into some form of object that I use later in the app.
However I can't get this multiline feature to work.. I've tried limiting the size. Setting the multiline flag. Disabling singleline. Giving lines, and minLines a random number (10).
Disabling horizontalscroll on the EditText. But nothing works....
Can anyone tell me what the hell I'm doing wrong? And how I can fix this horrid abomination of an EditText.
This is how my nightmare looks like now.
<EditText
android:id="#+id/callofedittext"
android:layout_width="wrap_content"
android:inputType="textMultiLine"
android:width="300dp"
android:minLines="10"
android:layout_height="wrap_content"
android:gravity="top|left"
android:textColor="#color/textWhite"
android:background="#color/textBlack"
android:paddingLeft="3dp"
android:singleLine="false"
android:scrollHorizontally="false"
>
<requestFocus />
</EditText>
It haunts my dreams...
EDIT: > Light at the end of the tunnel.
While I was focussing on the xml.. A new clean project pointed out to me that EditText textMessage = (EditText)findViewById(R.id.callofedittext); textMessage.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); is causing all of my problems. Not specifically the properties inside the xml.
From this comment, the inputType was set in the code as well with:
textMessage.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE |
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
This is actually not correct, because TYPE_TEXT_FLAG_MULTI_LINE and TYPE_TEXT_FLAG_CAP_SENTENCES are only flags, and do not contain the actual input type. In order for them to work, they must be layered as flags on top of InputType.TYPE_CLASS_TEXT. Without this type class flag, the edit text does not have a base input type class to apply your flags to, and defaults to no specified input type.
So, the correct way to set the input type with both of these flags is:
textMessage.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE |
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
For official details on how these flags work, see the Android Developer Docs on InputType and TextView - android:inputType
I'm not sure why the design decision is this. Personally, I think they should have hidden how they are representing their flags (as ints/bit flags), and instead had enums and/or subclasses of InputType for their public interface.
hey you have to add the following code in xml file ..
android:gravity="top"
android:maxLines="4"
android:inputType="textMultiLine"
android:scrollbars="vertical"
android:textSize="16sp"
android:padding="10dp"
and you have to put activity file ...
edtComment = (EditText) findViewById(R.id.edtComment);
edtComment.setMovementMethod(new ScrollingMovementMethod());
this is works for me and hope it will works for you .....
Have you tried using
android:layout_height="wrap content"
instead of
android:layout_height="match_parent"

android:imeOptions. Button not showing up

I tried setting android:imeOptions to actionSend, actionSearch. But there's no "Send" or "Search" button on the keyboard, just usual "Enter" key. I also tried setting different input types. (I'm working with HTC Sensation XL.) What's wrong?
I'd suggest switching your EditText to singleLine mode
Currently in Android Studio 2.2.3 if you use
android:singleLine="true"
IDE gives a warning that it has been deprecated use maxlines instead.
android:maxLines="1"
However maxLines does not solve the problem. The solution is to just add the attribute inputType. Example :
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/actionDoneDemo"
android:layout_below="#id/nameET"
android:imeOptions="actionDone"
android:hint="Action Done Demo"
android:inputType="text"/>
Try these actionDone imeOption doesn't work on EditText in Android 2.3
if it is not supported read How do I handle ImeOptions' done button click?. May be the HTC implemented their own soft keyboard which ignores the imeOptions
Just do in xml:
<EditText android:imeOptions="actionSearch"
android:inputType="text"/>
Happy Coding!!

How to make an EditText selectable but not editable on Android Ice Cream Sandwich?

I have a ListView in Activity, and in each item , I insert an EditText for show my text.
I need drag the handle to select text & copy the text, but can not edit text.
On Android ICS, How can I do this?
text.setTextIsSelectable(true) requires API 11. For those using lower API's:
In xml use:
android:inputType="none"
android:textIsSelectable="true"
This will make your EditText uneditable but selectable.
I think you could override the onKeyDown() method, make it do nothing but return true. It should catch the keypresses from the keyboard and negate them before they can go into the text in the EditText.
You might also try setting editable to false like this
android:editable="false"
on the EditText in your xml layout. However I am not certain if this will let you still highlight and copy, but it is worth a shot.
I resolved this problem.
Just set TextView like this:
text.setTextIsSelectable(true);
Althouth android:editable is deprecated and Lint suggests to use inputType, It doesn't seem to work. So android:editable="false"is apparently the best possible solution for all android versions.
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:editable="false"
android:textIsSelectable="true"
tools:ignore="Deprecated" />

Categories

Resources