You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用TextInputLayout和TextInputEditText后设计布局无法显示

TextInputLayout & TextInputEditText 设计页面无法正常显示的解决方案

你的布局中存在两个核心问题导致设计页面显示异常:

  • TextInputLayout设置了android:layout_height="match_parent",使其占满整个父容器,挤压了内部TextInputEditText的显示空间
  • TextInputEditText重复设置hint且存在拼写错误(Enter Passwrod)

修改后的布局代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SignUpActivity">

    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Password"
        android:layout_marginHorizontal="16dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="52dp"
            android:inputType="textPassword"
            android:lines="1"/>
    </com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

修改说明

  1. 调整TextInputLayout高度:将layout_height改为wrap_content,让容器根据内部EditText高度自适应,同时添加水平边距避免控件贴边
  2. 统一hint设置:移除TextInputEditText的hint,仅保留TextInputLayout的hint,确保Material Design浮动标签功能正常工作,同时修正原hint的拼写错误
  3. 优化约束:移除不必要的底部约束,避免强制让TextInputLayout撑满整个屏幕

你的依赖版本组合(Material 1.8.0 + AppCompat 1.6.1)无版本冲突,无需额外升级。

内容的提问来源于stack exchange,提问作者James Cheung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 02:45:27