Android TextInputLayout 提示与 EditText 提示重叠

标签 android android-layout android-edittext android-textinputlayout textinputlayout

我面临一个奇怪的问题,我有一个 InputTextLayout 和一个 EditText,我正在尝试实现这样的事情(如下图所示)(图片来自 Material 设计指南:https://material.io/guidelines/components/text-fields.html#text-fields-layout),其中有两个独立的提示。我通过向两种布局添加 android:hint 来做到这一点。这很好用,但是当焦点从这里移开时,“标签”向下移动并与“占位符”文本重叠。 (仅当用户未提供任何输入且编辑文本为空时 - 两个提示重叠)。有关如何解决此问题的任何指示?

作为一项要求,我需要两个提示都存在,并且“标签”不应随着焦点变化而向下移动。两个提示都应该保留在它们的位置上

 <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Label">

        <android.support.v7.widget.AppCompatEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Placeholder"
            android:inputType="textCapWords"
            />

    </android.support.design.widget.TextInputLayout>

enter image description here

最佳答案

enter image description here现在 Material 组件 (alpha03) 支持占位符文本:

  dependencies {
    // ...
    implementation 'com.google.android.material:material:1.2.0-alpha03'
    // ...
  }

  <com.google.android.material.textfield.TextInputLayout
      ...
      app:placeholderText="Placeholder text">

关于Android TextInputLayout 提示与 EditText 提示重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45453570/

相关文章:

android - 如何在日历 View 中显示数据库中的日期

java - Html.fromHtml(String) + 换行问题

Android 数据绑定(bind) src ImageView in xml

android - 如何在 Android EditText 上实现 DoubleClick?

android - 小 EditText 有一个带有很多行的 setError

android - CollapsingToolbarLayout 包含 ViewPager 和其中的搜索框。如何防止搜索框只折叠,而ViewPager折叠

android - "flutter run"卡在 "Running Gradle task ' assembleDebug"

android:dither ="true"不抖动,怎么了?

android - 无法完成 session : INSTALL_FAILED_INVALID_APK: Split lib_slice_0_apk was defined multiple times

android - 编辑文本大小不应改变 ImageView 的大小