想要使用提示自定义 EditText 属性

Want to customize EditText attribute with a hint

我是 android 移动开发和 java 的新手。想知道是否有人可以帮助我解决我的问题。

现在,我正在制作我的 android 应用程序的 XML 文件,并希望它具有如下所示的内容。

是否可以在XML文件中制作而不需要深入了解java?我只想在 EditText 属性中添加固定文本。使用 LinearLayout 到我的第一个应用程序。我感谢任何形式的帮助。

使用 API 28 进行测试。

这叫TextInputLayout.Readhere. Demo example here

  <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintEnabled="true">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Username" />

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

是的,有默认布局 TextInputLayoutTextInputEditText。 这是文档: https://developer.android.com/reference/android/support/design/widget/TextInputLayout https://material.io/develop/android/components/text-input-layout/

您正在查找 TextInputLayout 组件:

  <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Username"
        app:boxBackgroundColor="@color/white"
        app:boxStrokeColor="@color/text_input_layout_stroke_color"
        app:counterMaxLength="15"
        app:counterEnabled="true"
        >

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

    </com.google.android.material.textfield.TextInputLayout>