简体   繁体   English

我正在使用的所有4个仿真器设备中的EditText文本都不会重叠在清除按钮上,除了NEXUS 4

[英]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) 我的EditText有以下结果:( 从左到右)

Android Emulator:(Respectively) Android模拟器:(分别)
3.2QVGA API 15, Nexus S API 23 3.2QVGA API 15,Nexus S API 23
Nexus 5X API 23, Galaxy S7 API 24 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上,所有4台设备的结果都很好,结果如下:

NEXUS 4 API 22: NEXUS 4 API 22:

在此处输入图片说明

Here is my code: 这是我的代码:

XML: 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 : 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: 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 我什至尝试为firstNameText末端padding硬编码100dp的值

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

All the devices (4 emulators) text was pushed even further to the left/start expect Nexus 4 . 所有设备(4个仿真器)的文字都被进一步推到左侧,并开始连接Nexus 4 It's almost like the device edittext is not reacting to these padding. 几乎就像设备的edittext对这些填充没有反应。

You can simply add drawableRight in your AutoCompleTextView, don't even need ImageView . 您可以在AutoCompleTextView中简单地添加drawableRight,甚至不需要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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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