Android studio 带提示的EditText,提示移动的位置

Android studio 带提示的EditText,提示移动的位置,android-studio,kotlin,android-edittext,Android Studio,Kotlin,Android Edittext,我看到EditText有一个提示,当用户点击它时,提示会向上移动,减小字体大小,并使字段由用户编辑。当用户移动到另一个EditText并将其保留为空时,提示将以完整大小显示 它是什么?如何使用XML将其添加到Android Studio上的活动中 我在Android Studio上使用Kotlin。如果你是这个意思的话 是的 在build.gradle(模块:app)文件中添加设计支持库的依赖项,如下所示 implementation 'com.google.android.material:

我看到
EditText
有一个提示,当用户点击它时,提示会向上移动,减小字体大小,并使字段由用户编辑。当用户移动到另一个
EditText
并将其保留为空时,提示将以完整大小显示

它是什么?如何使用XML将其添加到Android Studio上的活动中

我在Android Studio上使用Kotlin。

如果你是这个意思的话

是的

build.gradle
(模块:app)文件中添加设计支持库的依赖项,如下所示

implementation 'com.google.android.material:material:<version>'
implementation 'com.android.support:design:25.3.1'

这是
TextInputLayout
,您可以在其中使用
editText
作为子项,如下所示:

   <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/activity_horizontal_margin">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Floating Hint Enabled Default" />

    </android.support.design.widget.TextInputLayout>
首先
build.gradle
文件中添加设计支持库的依赖项,如下所示

implementation 'com.google.android.material:material:<version>'
implementation 'com.android.support:design:25.3.1'
如果您使用的是
AndroidX

implementation 'com.google.android.material:material:1.0.0'
第二步,然后像这样实现:

   <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/activity_horizontal_margin">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Floating Hint Enabled Default" />

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

我添加了依赖项,当我同步时它会抛出错误。我试了第一个,当它抛出错误时,我也试了第二个。同步时两者都抛出错误。注意:我没有添加XML。Gradle sync失败:在项目“:org.Gradle.api.project类型的应用”上找不到参数[com.android.support:design:25.3.1]的方法实现()。有关更多详细信息,请参阅IDE日志(帮助|显示日志)(3 s 123 ms)NDK解析结果:项目设置:Gradle模型版本=5.4.1,NDK版本未知。Gradle(模块:app)在依赖项{}块中,我们有两个build.Gradle将其添加到正确的位置和您的build.Gradle(项目:yourproject)在allprojects->repositories块中添加这些:google()、jcenter()、maven{url''},它们修复了错误,但是,当我添加XML代码时,它会抛出一些错误。我将作为一个单独的注释添加它。我添加了您提供的XML代码(原样)是在启动按钮和编辑文本的代码之前。是的,这就是我的意思。然而,对于像我这样的初学者来说,这段代码是不够的,因为您没有提到添加依赖项,尽管XML代码是完美的。如果将依赖项部分添加到您的回复中,我可以选择此作为答案。@user3765415我已添加了依赖项OK。当我按原样添加代码时,您的代码工作得非常完美,但当我移动添加约束时,它并没有按预期工作。我给这两个部分留了相同的余量。你能检查出哪里出了问题吗?我想这是另一个问题!不,否则这没用。