42
votes

Whenever a word is typed in the EditText box, I always see an underline under the word being typed. But when I press a space after that word I no longer see the underline.

My reqirement is to remove that underline when the user is typing the message.

Added is the screenshot and we see that Smith is underlined. But I don't want this to happen.

Below is the xml that I use for the AlertDialog box.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView 
    android:id="@+id/name_view"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:text="@string/alert_dialog_name"
    android:gravity="left"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/username_edit"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:scrollHorizontally="true"
    android:autoText="false"
    android:inputType="textPersonName"
    android:capitalize="none"
    android:gravity="fill_horizontal"
    android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

enter image description here

10
The appearance of words currently being typed (at least with autocomplete on) varies from device to device. On HTC SenseUI on Android 2.2, for example, the current word under autocomplete consideration is shown with a green highlight. Why would you want to mess with what the user expects to see on the particular device/keyboard they're used to?Yoni Samlan
I just want to use whatever the user types and send it across to the server, I don't want any logic to be written to remove the last underlined word.Sana
This is IME-specific. If you want the IME to interfere as little as possible, you can use a different inputType, but in this case, you're using the right type, and it does what it thinks is best for this particular type of input, and that's what the user will expect too.EboMike
You don't have to use any logic to remove the underlines -- just call getText().toString() when you want to use the value. It won't include special formatting or anything.Yoni Samlan
OK, I added it as an answer so you can accept it, although I don't really consider it much of a problem or a solution -- it's just "ignore what it looks like and treat it like any normal text input."Yoni Samlan

10 Answers

11
votes

You don't have to use any logic to remove the underlines -- just call getText().toString() when you want to use the value. It won't include special formatting or anything.

66
votes

android:inputType="textNoSuggestions"

20
votes

There is a function that removes any composing state. I think if you call it after every time a user types, you will not see the underline. I use it after the user finishes typing, to get the drawing cache of the entire textView (which I need without underline). It's

someTextView.clearComposingText();
12
votes

accepted answer is not given solution, and some other user given answer but no one given full anser, so that's why i write here working solution.

If you want to remove underline then just add below code.

XML

android:inputType="textNoSuggestions"

Java

EditText ed;
ed = findViewById(yourId);
ed.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

If you want to set more than one input type then,

ed.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

May be above information is helpful to others.

5
votes

The best solution for this is to add on your EditText:

 android:inputType="textMultiLine|textVisiblePassword"
2
votes

Use this from your class, if EditText view is dynamic (created from class file):

EditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

OR include android:inputType="textNoSuggestions" with your EditText in XML.

2
votes

Read this if you want to keep emojis and textNoSuggestions doesn't work for you.

textNoSuggestions does not work in every keyboard. inputType="textVisiblePassword" works but it removes emoji's from most keyboards.

I found that setting inputType="textUri" works and keeps the ability to add emojis.

0
votes

try:

android:inputType= InputTypes.TextVariationVisiblePassword;
0
votes

You can set the EditText to have a custom transparent drawable or just use android:background="@android:color/transparent".

-2
votes
<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:imeOptions="actionDone"
        android:inputType="textNoSuggestions"
        android:maxLines="1"
        />