How to return to default style on EditText if I apply a background?
First, before you call setBackgroundResource with your own ninepatch, store the original background of the EditText, like this:
Drawable originalDrawable = myEditText.getBackground();
Then, if the user entered the wrong data, you can set your red border ninepatch:
myEditText.setBackgroundResource(R.drawable.edittext_red);
And later, when you want to restore the look of the EditText, use the stored drawable:
myEditText.setBackgroundDrawable(originalDrawable);
Alternatively you can reference the default Android EditText background directly like this:
myEditText.setBackgroundResource(android.R.drawable.edit_text);
At androiddrawables you can see how the different drawables look for the different versions of Android, and get their resource identifier. This method should work for all drawables, not just EditText
These (and other android resources) can also be found on your own system, in the android-sdk folder in
< path to android-sdk folder>/android-sdk/platforms/android-< API level>/data/res/
For material design with Kotlin:
edit.apply {
setBackgroundResource(androidx.appcompat.R.drawable.abc_edit_text_material)
}