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

。_饼干妹妹 提交于 2019-11-30 04:16:34

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.

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

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.

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.

Liam Tech

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

 android:inputType="textMultiLine|textVisiblePassword"

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.

asaf

try:

android:inputType= InputTypes.TextVariationVisiblePassword;

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

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:imeOptions="actionDone"
        android:inputType="textNoSuggestions"
        android:maxLines="1"
        />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!