How to set TextInputLayout error message colour?

前端 未结 9 2202
旧巷少年郎
旧巷少年郎 2020-11-27 13:58

How can I change the colour of the error message that can be set to appear below the text field in a TextInputLayout (via setError(...) – see error

9条回答
  •  -上瘾入骨i
    2020-11-27 14:50

    UPDATE

    Please use a custom view instead and not this


    A modded version of @jared's Answer which works in my case :

    public static void setErrorTextColor(TextInputLayout textInputLayout, int color) {
        try {
            Field fErrorView = TextInputLayout.class.getDeclaredField("mErrorView");
            fErrorView.setAccessible(true);
            TextView mErrorView = (TextView)fErrorView.get(textInputLayout);
            mErrorView.setTextColor(color);
            mErrorView.requestLayout();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题