2

The character counter changes the floating label color when max length, but calling setError() does not change it.

Screenshot

I tried app:errorTextAppearance="@style/MyErrorText".

style/MyErrorText:

<style name="MyErrorText" parent="TextAppearance.AppCompat.Small">
    <item name="android:textColor">@color/error_color</item>
</style>

And I also tried setErrorEnabled(true). However, they made no change. Is there a way to change the floating label color when calling setError()?


xml code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="@dimen/spacing_big"
        android:paddingRight="@dimen/spacing_big"
        android:paddingTop="@dimen/spacing_small">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/text_input_layout_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:counterEnabled="true"
            app:counterMaxLength="25"
            app:theme="@style/CustomTilTheme"
            android:layout_marginBottom="@dimen/spacing_small">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/list_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/name_hint"
                android:textSize="@dimen/text_normal">

                <requestFocus/>
            </android.support.design.widget.TextInputEditText>
        </android.support.design.widget.TextInputLayout>

        ......

    </LinearLayout>
</ScrollView>

style/CustomTilTheme:

<style name="CustomTilTheme" parent="Theme.Design.Light">
    <item name="colorControlActivated">@color/accent_color</item>
</style>

java code:

    ......

    final TextInputLayout textInputLayoutName = (TextInputLayout) dialogLayout.findViewById(R.id.text_input_layout_name);
    textInputEditText = (TextInputEditText) dialogLayout.findViewById(R.id.list_name);
    textInputEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            int size = s.length();

            if (size < 1) {
                textInputLayoutName.setError("1文字以上入力してください");
            } else if (size > 25) {
                textInputLayoutName.setError("25文字以内で入力してください");
            } else {
                textInputLayoutName.setError(null);
            }
        }
    });
    if (args == null) {
        textInputLayoutName.setError("1文字以上入力してください");
    } else {
        textInputEditText.setText(args.getString("list_name"));
    }

    ......

I'm using

  • Support Library 23.3.0
  • SDK Tools 25.1.3
  • SDK Platform Tools 23.1
  • Build Tools 23.0.3

This app runs on Nexus 5 API23 (Official Android Emulator).

Cyanoa
  • 21
  • 3

1 Answers1

0

If you change TextInputLayout floating label color to blue:

 <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_register_firstname"
                android:textColor="@color/blue"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

Sorry i cant upload photo can you try this

Especially this is a quick answer, you can create more detailed style like this answer

Community
  • 1
  • 1
Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58