How to remove underline edittext android

Android — Remove totally underline from EditText

I have this EditText on my Android app:

and when I type something on it, the word it’s underline.

I know that it is because of the auto suggestion of Android and it can be solved with android:inputType=»textNoSuggestions» so please avoid answers that just say to me what I know.

The problem comes when I add the attribute that I put above to the EditText , because it change its form. For example, if the EditText its like:

when I add the attribute android:inputType=»textNoSuggestions» its form change to something like this:

And on the bottom of the layout a white block appears (maybe because the EditText are white, I suppose that) with a size more or less as the EditText that has changed (the second one) but in this block I can’t interact. Something like this:

With the attribute android:inputType=»textNoSuggestions» when I type words manually on the EditText they aren’t underline but when I use the Swype function of my keyboard, they are underline again.

Also, I don’t want that this attribute changes the EditText even more if it creates a block on the bottom of the Layout.

Therefore, what I want to know:

1) Is it possible to totally remove the underline of the words that are entered into the EditText ? It doesn’t matter if it is manually, by Swype or whatever.

2) How can I remove the underline of the words of my EditText but without changing the EditText or that a block appears on my Layout ?

EDIT: Here I add two photos in which you can see the problem:

1) Before add the attribute.

2) After add the attribute.

EDIT 2: Here it’s my rounded_corners background:

Источник

remove additional underline in EditText

I have EditText with custom background drawable:

I’m using android databinding library and MVVM architecture.

If ViewModel has isAllowEdit set to true than EditText background set to @drawable/profile_et_background_active.

Читайте также:  Зарядка через wifi для андроида

If isAllowEdit false EditText has background set to @drawable/profile_et_background.

Also i’m disallow edit by setting inputType to TYPE_NULL, and allow edit by setting inputType to TYPE_CLASS_TEXT.

When edit is allowed and user start typing text in EditText additional underline appears under typed word (it belongs only to currently typed word, all other parts of EditText text has no underline):

I tried to remove that underline by adding color filter to EditText:

But it doesn’t work.

How can i remove that extra underline ?

UPDATE 1

I already tried to add @android:color/transparent, and I’m getting error:

«java.lang.Integer cannot be cast to android.graphics.drawable.Drawable»

UPDATE 2

Adding InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS does not work for me. So i guess this is not Spell Checker’s problem.

7 Answers 7

The underline text styling is applied by the BaseInputConnection of EditText to the text currently being «composed» using the styling applied by the theme attribute android:candidatesTextStyleSpans , which by default is set to the string candidates .

Источник

Android edittext is underlined when typing

I need to removed underline when type in edit text field in Android. For the first name edit text first letter should be capital so that I have given textCapSentences , but in my case I see underline in edittext fields. how to remove that?

I have tried all the combination of textFilter|textNoSuggestions|textCapSentences

its my first name edit text:

6 Answers 6

android:inputType=»textVisiblePassword» disabling text autocorrection

None of the other answers were useful for me. This underline is added to suggest words when writing. This is enabled by a setting on your keyboard app (Gboard in my case).

So there are at least three options you can do:

Do nothing as this is a setting on an external app (Gboard) and is the user who should handle it.

Ask the user to disable it and show instructions to explain how to do it. This is: To navigate to gboard settings from settings app or also from an opened keyboard and click on the Settings button, then go to «text/spell correction» or similar and disable the first switch: Show suggestion strip

Remove it by your self. As Gboard adds an UnderlineSpan to the EditableText in EditTexts you can remove it just first looking for it. The underline is added by Gboard at some point between onTextChanged and afterTextChanged so I had to remove it on afterTextChanged method.

Читайте также:  Как узнать сколько лет моему телефону андроид

Источник

How to change line color in EditText

I am creating an EditText in my layout xml file

But I want to change color line in EditText from Holo to (for example) red. How that can be done?

21 Answers 21

This is the best tool that you can use for all views and its FREE many thanks to @Jérôme Van Der Linden.

The Android Holo Colors Generator allows you to easily create Android components such as EditText or spinner with your own colours for your Android application. It will generate all necessary nine patch assets plus associated XML drawable and styles which you can copy straight into your project.

UPDATE 1

This domain seems expired but the project is an open source you can find here

this image put in the background of EditText

UPDATE 2

For API 21 or higher, you can use android:backgroundTint

Update 3 Now We have with back support AppCompatEditText

Note: We need to use app:backgroundTint instead of android:backgroundTint

Update 4 AndroidX version

I don’t like previous answers. The best solution is to use:

android:backgroundTint for EditText works only on API21+ . Because of it, we have to use the support library and AppCompatEditText .

Note: we have to use app:backgroundTint instead of android:backgroundTint

AndroidX version

You can also quickly change the EditText’s underline color by tinting the background of the EditText like so:

for API below 21, you can use theme attribute in EditText put below code into style file

use this style in EditText as

Programmatically, you can try:

Its pretty simple (Required: Minimum API 21).

  1. Go to your xml and select the EditText field
  2. On the right side, you can see the ‘Attributes’ window. Select ‘View All Attributes’
  3. Just search for ‘tint’
  4. And add/change the ‘backgroundTint’ to a desired color hex (say #FF0000)

i think the best way is by theme:

You can change the color of EditText programmatically just using this line of code: edittext.setBackgroundTintList(ColorStateList.valueOf(yourcolor));

Читайте также:  Возможности андроида для телевизора

To change Edittext’s underline color:

If you want the entire app to share this style, then you can do the following way.

(1) go to styles.xml file. Your AppTheme that inherits the parent of Theme.AppCompat.Light.DarkActionBar (in my case) will be the base parent of all they style files in your app. Change the name of it to “AppBaseTheme’. Make another style right under it that has the name of AppTheme and inherits from AppBaseTheme that you just edited. It will look like following:

Then change the “colorAccent” to whatever the color you want your EditText line color to be.

Источник

How can I remove all default padding from EditText?

I am using an EditText and it always adds a bit of padding in my text to both left and right.
Adding android:includeFontPadding=»false» did not help and using negative android:layout_marginLeft or android:layout_marginRight just makes the EditText «expand».
How can I strip all padding from the EditText that is being added by default?

3 Answers 3

To remove the padding on the left and right of the EditText , you can use the following:

If you also want to remove underline padding add negative margin:

Indeed EditText has its own drawable padding which remains even after setting all paddings/margins to zero in xml. To fully remove padding from EditText you have to remove it from its drawable which in fact is InsetDrawable.

You can cast your drawable to InsetDrawable , get the original drawable via getDrawable() method. That original drawable doesn’t have additional spacing at all and you can set it as a new background via setBackground() to your EditText widget.

But you’d rather want it to save its top and bottom insets, because otherwise EditText looks ugly.

To preserve horizontal spacing you have to subtract original padding dimensions from inset drawable padding dimensions. I assume that padding is calculated by summing original drawable padding and inset drawable insets. So to retrieve only insets you have to perform subtraction.

Here is full example (Corresponds to «removed spacing only horizontal» EditText on picture):

Источник

Оцените статью