Как установить выравнивание текста ошибки по центру в TextInputLayout - PullRequest
0 голосов
/ 14 февраля 2019

Как выровнять текстовое сообщение об ошибке по центру и ниже от правки текста. Я попытался выровнять, но он не работает. Вот мой код:

enter image description here

Xml

<android.support.design.widget.TextInputLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tilEmail">
 <EditText
                    android:layout_width="match_parent"
                    android:id="@+id/mob"
                    android:layout_height="35dp"
                    android:background="@drawable/round_corner_3"
                    android:inputType="phone"
                    android:hint="Mobile Number"
                    android:textColorHint="@color/colorGray"
                    android:textColor="@color/Black"
                        android:drawablePadding="10dp"/>
                </android.support.design.widget.TextInputLayout>

Java класс

til = (TextInputLayout) findViewById(R.id.tilEmail);

                     til.setError("Mobile number not valid");

                     til.setError(Html.fromHtml("<font color='red'>Mobile number not valid</font>"));
                    mobile.setError(null);

         mobile.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                    Toast.makeText(getApplicationContext(), "Phone number or Password is not valid", Toast.LENGTH_SHORT).show();

                }

1 Ответ

0 голосов
/ 14 февраля 2019
// reference an error textview
TextView textView = (TextView) til.findViewById(android.support.design.R.id
            .textinput_error);

if (textView != null) {
    // can be RelativeLayout/FrameLayout Params, depending on your xml
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams();
    params.gravity = Gravity.CENTER|Gravity.BOTTOM;
    textView.setLayoutParams(params);
}

Кроме того, вы можете добавить поля к LayoutParams

...