Skip to content Skip to sidebar Skip to footer

How To Group Together A Label And A Textview Together In Android?

I want to group together the label (e.g. 'StaffID') and the value of the textView (e.g. 'S1234567') together, vertically, in Android. The label stays on top the textView value thro

Solution 1:

Wrap the edit text with TextInputLayout with the desired android:hint attribute.

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

check the official docs for more info and features

Solution 2:

<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>

Post a Comment for "How To Group Together A Label And A Textview Together In Android?"