How to set different gravity for TextInputLayout's hint and text entered in edit text. I want to set the hint gravity to start and edit text's text gravity to center. So how can i achieve this. This is my xml code,
<android.support.design.widget.TextInputLayout
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="start">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/grey"
android:hint="Email"
/>
</android.support.design.widget.TextInputLayout>
EditText
is added to theTextInputLayout
, which will happen during inflation, in this case. To set a different gravity for theEditText
, don't set anygravity
attributes in the layout, then set theEditText
's gravity programmatically, in your code. That is, aftersetContentView()
, usefindViewById()
to get theEditText
, then callsetGravity(Gravity.CENTER_HORIZONTAL)
on it. – Harrold