Change background of EditText's error message

前端 未结 4 849
情歌与酒
情歌与酒 2020-12-02 14:21

What I want to do is change the background color (set custom drawable) of a popup error message displayed after using setError() method.

Currently, it l

4条回答
  •  难免孤独
    2020-12-02 14:57

    You can use this method just pass msg text,your edittext id

     public static void setErrorMsg(String msg,EditText viewId)
    {
        //Osama ibrahim 10/5/2013
        int ecolor = Color.WHITE; // whatever color you want
        String estring = msg;
        ForegroundColorSpan fgcspan = new ForegroundColorSpan(ecolor);
        SpannableStringBuilder ssbuilder = new SpannableStringBuilder(estring);
        ssbuilder.setSpan(fgcspan, 0, estring.length(), 0);
        viewId.setError(ssbuilder);
    
    }
    

提交回复
热议问题