2

I create simple style.xml file

<style name="You.EditText.Style" parent="@android:style/Widget.EditText">
    <item name="android:textColor">@color/colorRed</item>
    <item name="android:gravity">center</item>
</style>

But all EditTexts I create dynamically. How I can declare my style to EditText attribute?

vektor
  • 3,312
  • 8
  • 41
  • 71
user1582087
  • 93
  • 1
  • 3
  • 10

2 Answers2

2

Instantiate your EditText view like this:

EditText e = new EditText(context, null, R.style.You_EditText_Style);
Paul Burke
  • 25,496
  • 9
  • 66
  • 62
0

You can do this with the EditText#setTextAppearance(context, resid) method.

Example:

myEditText.setTextAppearance(getApplicationContext(), R.style.id);

See EditText reference.

endowzoner
  • 2,238
  • 3
  • 17
  • 20