1

Additional constraints: both edit fields are placed to each other horizontally and the hint is long enough to be above them

Long enough hint above two edit fields

======= ==================

enter image description here

Sorel
  • 91
  • 6

2 Answers2

1

It's impossible for TextInputLayout to have 2 EditText as children. Doing this throws you an InflateException like this :

android.view.InflateException: Binary XML file line #xxx: We already have an EditText, can only have one

So I assume that it's a Material Design guideline, and having one TextInputLayout with 2 EditText is anti-pattern to google's recommandations.

Rami
  • 158
  • 1
  • 8
0

Try this:

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:gravity="center"
        android:text="Only one hint above two edit fields"
        android:textSize="20dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/et1"
            />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/et2"
            />
    </LinearLayout>
</LinearLayout>

If you ant to hide the TextView, you can use a TextChangedListener and set the Visibilty to INVISIBLE if the text equals "".

Jakob
  • 1,858
  • 2
  • 15
  • 26