如何在Android中将标签和textView组合在一起?

时间:2021-01-13 08:49:17

标签: android android-layout

我想在 Android 中垂直地将标签(例如“StaffID”)和 textView 的值(例如“S1234567”)组合在一起。当用户在 textView 中输入值时,标签始终位于 textView 值的顶部。附件是我想要的 UI 的截图。

Click here to view the UI screenshot

2 个答案:

答案 0 :(得分:1)

用带有所需 TextInputLayout 属性的 android:hint 包裹编辑文本。

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

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

查看official docs了解更多信息和功能

答案 1 :(得分:0)

<android.support.design.widget.TextInputLayout
    android:id="@+id/inputlayout"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:theme="@style/loginActivityHintStyle">

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="@string/the_hint_that_shows_with_the_editext"
        android:inputType="text"
        android:labelFor="@+id/edittext"
        android:maxLength="15"
        android:textColor="@drawable/login_activity_input_text_color" />

</android.support.design.widget.TextInputLayout>
相关问题