开发者

How to remove the underline from the EditText field in Android?

开发者 https://www.devze.com 2023-02-20 22:14 出处:网络
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.

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_vi开发者_如何学运维ew"
    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>

How to remove the underline from the EditText field in Android?


android:inputType="textNoSuggestions"


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();


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.


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.


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

 android:inputType="textMultiLine|textVisiblePassword"


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.


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.


try:

android:inputType= InputTypes.TextVariationVisiblePassword;


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号