android - 无法将 TextInputEditText 放置在 TextInput 布局的顶部。安卓工作室
问题描述
所以我遇到了一个问题,我试图在 com.google.material 库的 TextInputLayout 下将我的 EditText 转换为 TextInputEditText。
我无法将我的 TextInputEdit 文本放在 TextInputLayout 的顶部 这是一个屏幕截图。
正如你所看到的,它从顶部和左侧都有点偏离。
登录.xml
<com.google.android.material.textfield.TextInputLayout
android:layout_width="210dp"
android:layout_height="53dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:background="@drawable/roundedittext"
android:ems="10"
android:hint=" Email"
android:importantForAutofill="no"
android:inputType="textEmailAddress"
android:padding="5dp"
app:errorEnabled="true"
tools:layout_editor_absoluteX="101dp"
tools:layout_editor_absoluteY="366dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/signupemailfeild"
android:layout_width="210dp"
android:layout_height="47dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="210dp"
android:layout_height="47dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@drawable/roundedittext"
android:ems="10"
android:hint=" Password"
android:importantForAutofill="no"
android:inputType="textPassword"
android:padding="5dp"
app:errorEnabled="true"
app:passwordToggleEnabled="true"
tools:layout_editor_absoluteX="101dp"
tools:layout_editor_absoluteY="444dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/signuppasswordfeild"
android:layout_width="match_parent"
android:layout_height="47dp"
android:hint="Password"
android:inputType="textPassword"
tools:layout_editor_absoluteX="match_parent"
tools:layout_editor_absoluteY="match_parent" />
</com.google.android.material.textfield.TextInputLayout>
build.gradle(应用程序:模块)
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-database:19.3.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'com.github.castorflex.smoothprogressbar:library:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.mediarouter:mediarouter:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
更新:- 修复了 X 轴偏移 现在问题仅在于 Y 轴偏移。 单击此处获取新屏幕截图
解决方案
应用这些更改:
- 使用最新稳定版的 Material Components
implementation 'com.google.android.material:material:1.1.0'
- 用
android:layout_height="wrap_content"
在TextInputLayout
android:padding="5dp"
中删除TextInputLayout
- 用
android:layout_height="match_parent"
在TextInputEditText
android:hint=" Password"
中删除TextInputEditText
- 更改
app:passwordToggleEnabled="true"
为app:endIconMode="password_toggle"
只需使用:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint=" Password"
android:importantForAutofill="no"
app:errorEnabled="true"
app:endIconMode="password_toggle"
...>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/signuppasswordfeild"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPassword"
/>
</com.google.android.material.textfield.TextInputLayout>
推荐阅读
- c# - 将 XML 更新为 varchar SQL 列时出现问题
- node.js - 节点获取超时问题/快速超时/ lambda 超时或其他?
- flutter - 使 ColorTween 前进立即结束并正常反转而无需更改控制器?
- python - 如何指示哪个模型的字段引发了 ValidationError?
- python - 尝试通过发布请求从外部网站购买商品
- python - 如何用字典值替换列表/数组中的元素?
- django - Django (DRF) - 根据子属性过滤递归字段中的父级
- python-3.x - 如何克服 DataReader Iterrows 循环中缺少数据的错误?
- javascript - 当用户在我的 Discord 机器人上触发错误时,我如何向用户回复消息?
- google-cloud-platform - 如何修复 GCP OCR 返回 null 以限制文本的多边形顶点?