简体   繁体   中英

EditText text not overlapping over clear button in all 4 emulator devices I'm using, EXCEPT NEXUS 4

I have the following result in my EditText : (from left to right)

Android Emulator:(Respectively)
3.2QVGA API 15, Nexus S API 23
Nexus 5X API 23, Galaxy S7 API 24

在此处输入图片说明

Results in all 4 of devices are fine expect on my Nexus 4 where the result is the following:

NEXUS 4 API 22:

在此处输入图片说明

Here is my code:

XML:

<android.support.design.widget.TextInputLayout
                android:id="@+id/firstNameTextInput"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1">

                <AutoCompleteTextView
                    android:id="@+id/firstNameText"
                    style="@style/body_text_style"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_first_name"
                    android:imeOptions="actionNext"
                    android:inputType="textPersonName"
                    android:maxLines="1"
                    android:paddingEnd="@dimen/black_clear_button_square_length"
                    android:paddingRight="@dimen/black_clear_button_square_length"
                    tools:ignore="RtlSymmetry" />

                <ImageView
                    android:id="@+id/firstNameClearButton"
                    android:layout_width="@dimen/black_clear_button_square_length"
                    android:layout_height="@dimen/black_clear_button_square_length"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_gravity="end|center_vertical"
                    android:layout_marginEnd="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginTop="-32dp"
                    android:visibility="gone"
                    app:srcCompat="@drawable/ic_clear_black_svg" />

            </android.support.design.widget.TextInputLayout>

styles.xml :

<style name="body_text_style" parent="TextAppearance.AppCompat.Body1">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">@color/regular_black</item>
        <item name="android:textSize">@dimen/body_text_view_size</item>
        <item name="android:fontFamily">sans-serif-light</item>
    </style>

dimens.xml:

mdpi: <dimen name="body_text_view_size">13sp</dimen>
hdpi: <dimen name="body_text_view_size">13.5sp</dimen>
xhdpi: <dimen name="body_text_view_size">14sp</dimen>
xxhdpi: <dimen name="body_text_view_size">14.5sp</dimen>
xxxhdpi: <dimen name="body_text_view_size">15sp</dimen>

mdpi: <dimen name="black_clear_button_square_length">20dp</dimen>
hdpi: <dimen name="black_clear_button_square_length">21dp</dimen>
xhdpi: <dimen name="black_clear_button_square_length">22dp</dimen>
xxhdpi: <dimen name="black_clear_button_square_length">23dp</dimen>
xxxhdpi: <dimen name="black_clear_button_square_length">24dp</dimen>

Tries:
I even tried to hardcode a value of 100dp for end padding for my firstNameText

android:paddingEnd="100dp"
android:paddingRight="100dp"

All the devices (4 emulators) text was pushed even further to the left/start expect Nexus 4 . It's almost like the device edittext is not reacting to these padding.

You can simply add drawableRight in your AutoCompleTextView, don't even need ImageView . Here is the modified layout.

<android.support.design.widget.TextInputLayout
            android:id="@+id/firstNameTextInput"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/firstNameText"
                style="@style/body_text_style"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prompt_first_name"
                android:imeOptions="actionNext"
                android:inputType="textPersonName"
                android:maxLines="1"
                android:drawableRight="@drawable/ic_clear_black_svg" // added new
                android:paddingEnd="@dimen/black_clear_button_square_length"
                android:paddingRight="@dimen/black_clear_button_square_length"
                tools:ignore="RtlSymmetry" />
</android.support.design.widget.TextInputLayout>

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