簡體   English   中英

我正在使用的所有4個仿真器設備中的EditText文本都不會重疊在清除按鈕上,除了NEXUS 4

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

我的EditText有以下結果:( 從左到右)

Android模擬器:(分別)
3.2QVGA API 15,Nexus S API 23
Nexus 5X API 23,Galaxy S7 API 24

在此處輸入圖片說明

在我的Nexus 4上,所有4台設備的結果都很好,結果如下:

NEXUS 4 API 22:

在此處輸入圖片說明

這是我的代碼:

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>

嘗試:
我什至嘗試為firstNameText末端padding硬編碼100dp的值

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

所有設備(4個仿真器)的文字都被進一步推到左側,並開始連接Nexus 4 幾乎就像設備的edittext對這些填充沒有反應。

您可以在AutoCompleTextView中簡單地添加drawableRight,甚至不需要ImageView 這是修改后的布局。

<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