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,061
  • 6
  • 42
  • 69
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,308
  • 9
  • 64
  • 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,168
  • 3
  • 16
  • 20