// Declare and initialize
TextInputLayout textInputLayout = (TextInputLayout) view.findViewById(R.id.input_layout_name);
// If error
textInputLayout.setError("Username and password must be greater an 5 characters");
// If no error
textInputLayout.setErrorEnabled(false);