Reputation: 3951
I have this layout:
<LinearLayout
android:id="@+id/dialogCentralContent"
android:gravity="center_horizontal"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_below="@+id/phoneNumberInfo"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:background="@drawable/edittext_white_rounded">
<EditText
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:maxLines="1"
android:inputType="none"
android:focusable="false"
android:text="@={dataContext.phonePrefix}"
style="@style/Widget.App.PurchaseAmountEditText" />
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
tools:errorEnabled="true"
app:errorText="@{dataContext.validator.phoneValidation}">
<android.support.design.widget.TextInputEditText
android:layout_height="60dp"
android:layout_width="match_parent"
android:gravity="center"
android:maxLines="1"
android:inputType="phone"
android:text="@={dataContext.phoneNumber}"
style="@style/Widget.App.PurchaseAmountEditText" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
It looks like this:
As you can see the second EditText
is rendered lower than the first one. When I look at it in the visual editor of Android Studio I can see that the TextInputLayout
has some free space at its top, however setting paddingTop="0dp"
didn't change anything. So how to make those two EditText
s render the same way?
Upvotes: 3
Views: 1681
Reputation: 39191
By default, android.support.design.widget.TextInputLayout
will leave room at the top for the floating hint text. If you're not using the floating hint, you can remove that space by adding the following to the opening <TextInputLayout>
element.
app:hintEnabled="false"
The regular hint text will still be visible on the TextInputEditText
when it's empty.
N.B. – This answer does not apply to the current Material Components version, which is markedly different than the original.
Upvotes: 7