0

Hi I have a view with a form, and all button, labels, EditText, etc, are defined in a styles files, for example, for EditText I have app_edit_text and app_edit_text_error, my question is how can change in EditText the style from app_edit_text to app_edit_text_error?.

Thanks!

Pratik Butani
  • 56,749
  • 54
  • 254
  • 407
Tlaloc-ES
  • 3,690
  • 5
  • 26
  • 62

2 Answers2

2

To be honest you can't change style programaticaly. You can only change text appearance using setTextAppearance(int resId) method: https://developer.android.com/reference/android/widget/TextView#setTextAppearance(int)

For your purpose you can use setError(String error) method of EditText or implement self states and handle it in EditText subclass. Here is good post about custom states: How to add a custom button state

Paweł Dedio
  • 1,238
  • 12
  • 20
0

You can't change styles programatically. You can either replace them with a new Instance (you can specify the styles in the constructor only) or you can use it with a new theme since theme can be changed programatically. Themes

Steven97102
  • 179
  • 4
  • 14