In my experience, this is the best way:
EditText yourEditText;
yourEditText.setError("Input must be 4 digits and numeric");
Result:

Also, if the input should be numeric, use android:inputType="numberSigned"in the definition EditText. Thus, the device will not allow the user to enter non-numeric values; even better, a special keyboard will be shown for this:

source
share