无法将 TextInputEditText 置于文本输入布局之上。安卓工作室

Cannot place TextInputEditText on Top of TextInput Layout. AndroidStudio

所以我 运行 遇到了一个问题,我试图将我的 EditText 转换为 com.google.material 库中 TextInputLayout 下的 TextInputEditText。

我无法将我的 TextInputEdit 文本放在 TextInputLayout 之上 这是一个截图。

如您所见,它与顶部和左侧都有点偏离。

login.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 轴偏移有关。 Click Here For New Screenshot

尝试将 TextInputEditText 的 android:layout_width 和 android:layout_height 设置为“match_parent”,如果需要,您也可以尝试从 TextInputLayout 中删除 android:padding="5dp"非常适合。同时从第二个 TextInputLayout 中删除 android:hint="Password"。这就是为什么您会收到双重密码提示的原因。

应用这些更改:

  • 使用 Material 组件的最新稳定版本 implementation 'com.google.android.material:material:1.1.0'
  • TextInputLayout
  • 中使用 android:layout_height="wrap_content"
  • 删除 TextInputLayout
  • 中的 android:padding="5dp"
  • TextInputEditText
  • 中使用 android:layout_height="match_parent"
  • 删除 TextInputEditText
  • 中的 android:hint=" Password"
  • 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>