简体   繁体   中英

EditText bug, on focus it has white line next to on both left and right border side [Android]

I have found a bug in Android. I have very basic layout.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <com.google.android.material.textfield.TextInputEditText
        android:layout_margin="50dp"
        android:layout_width="0dp"
        android:layout_height="60dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

I wanted to have on Focus black bottom border background. So I changed in themes.xml

    <item name="colorSecondary">@color/black</item>

With this change when I press EditText/ TextInputEditText you can see small horizontal white lines next to it. Screenshot shows only left side, because I needed to zoom it.

在此处输入图像描述

What is causing the issue? This happens on S9+ and Pixel 4XL.

This is likely happening due to a combination of android:layout_margin="50dp" and colorSecondary . I don't think colorSecondary is the intended attribute to change here.

Theming a TextInputLayout is frustrating, butthis serves as excellent documentation . It states that you should override mtrl_textinput_default_box_stroke_color in color.xml

You can also reference these similar customizations I made here:

https://github.com/gavingt/upcoming-games/blob/master/app/src/main/res/values/styles.xml

https://github.com/gavingt/upcoming-games/blob/master/app/src/main/res/color/text_input_layout_box_stroke.xml

https://github.com/gavingt/upcoming-games/blob/d59dd2afd2ef7448ca2e826b0514e7db05195538/app/src/main/res/layout/fragment_filter.xml#L206

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM