user1582087
user1582087

Reputation: 93

Android styles and themes

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?

Upvotes: 2

Views: 173

Answers (2)

Paul Burke
Paul Burke

Reputation: 25584

Instantiate your EditText view like this:

EditText e = new EditText(context, null, R.style.You_EditText_Style);

Upvotes: 2

endowzoner
endowzoner

Reputation: 2298

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

Example:

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

See EditText reference.

Upvotes: 0

Related Questions