Set View style dynamically

Ask A Question

Login To post a question

I’m trying to dynamically create a TextView and then set a style which I previously defined in XML.

This is the XML which I defined in styles.xml:

<style name="box_area">
    <item name="android:layout_width">30dp</item>
    <item name="android:layout_height">30dp</item>
    <item name="android:background">@android:color/holo_red_dark</item>

Java Code:

TextView tv = new TextView(this, null,;

I don’t know which is the reason, but the style is not being applied.
Thank you

For more info please click here

Have a question or need a custom quote?