Center text vertically inside Android material TextInputLayout when it has fixed height in DP

24 Views Asked by At

I have a TextInputLayout which I want to have its height defined explicitly in DP.

When I tried that, the text was not aligned inside TextInputLayout vertically in center. This question already asked something like this but it did not receive enough attention and did not have updated answers yet and the suggested solution is not working fine.

As you might see it will be something like this:

enter image description here

Here is my layout XML:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="200dp"
        android:orientation="vertical">
    <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/TextInputLayoutPassword"
            style="@style/CustomInputLayout"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginStart="32dp"
            android:layout_marginTop="30dp"
            android:layout_marginEnd="32dp"
            android:padding="5dp"
            android:layout_below="@+id/textViewMainTitle"
            android:layout_centerHorizontal="true"
            android:textAlignment="viewStart"
            app:hintTextAppearance="@style/TextLabel"
            android:textColorHint="@color/text_input_layout_stroke_color"
            app:hintTextColor="@color/text_input_layout_hint_color"
            android:hint="@string/userPassword"
            app:endIconMode="clear_text"
            app:boxStrokeWidth="2dp"
            app:boxCornerRadiusBottomEnd="18dp"
            app:boxCornerRadiusTopEnd="18dp"
            app:boxCornerRadiusBottomStart="18dp"
            app:boxCornerRadiusTopStart="18dp">
        <!--this is the actual edit text which takes the input-->
        <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/textInputEditTextPassword"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"

                android:inputType="textPassword"
                android:layout_marginTop="10dp"
                android:textSize="20sp"
                android:layout_width="match_parent"
                android:cursorVisible="false"
                android:layout_height="wrap_content" />
    </com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
0

There are 0 best solutions below