android - 在我正在使用的所有 4 个仿真器设备中,EditText 文本不与清除按钮重叠,除了 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>
样式.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>
尺寸.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>
尝试:我什至尝试为我
的 end 硬编码一个 100dp 的值padding
firstNameText
android:paddingEnd="100dp"
android:paddingRight="100dp"
所有设备(4 个模拟器)的文本都被推到了左边/开始期待Nexus 4。几乎就像设备编辑文本对这些填充没有反应一样。
解决方案
您可以简单地在 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>
推荐阅读
- html - 我的下拉菜单正在向下推动其他 html 元素
- c# - 列出目录中 id 不是 Google Drive API v3 和 C# 中特定值的文件夹
- javascript - 监听关闭事件反应导航
- java - 导入 Sceneform 资源时出现致命 IDE 错误
- node.js - 在 React JS 中监控多个服务器统计信息
- security - 如何在短时间内检测到被篡改的大文件?
- elasticsearch - 搜索完整的单词
- javascript - Reactjs:对话框打开不适用于按钮单击
- sql - sql join 概念——性能调优
- dart - Dart 不必要的包导入是否有任何性能缺陷?