views:

57

answers:

0

Is there any way of applying styles defined in styles.xml to views created

programatically? I need to display textviews on the screen, and align them to different

positions on the screen. I am able to apply color and text size using

setTextAppearance() method, but I'm not able to apply other attributes like alignment

and padding. The styles i've user are :

<style name="style1">
    <item name="android:background">#00FFFF</item>
    <item name="android:layout_gravity">left</item>
    <item name="android:textSize">70dip</item>
    <item name="android:padding">67dip</item>       
</style>
<style name="style2" parent="@android:style/TextAppearance">
    <item name="android:textColor">#2F4F4F</item>
    <item name="android:layout_gravity">bottom</item>
</style>

And the java code is like...

TextView t = new TextView(this);
t.setText("Hello");
t.setTextAppearance(this, R.style.style1);

Can someone please help me with this... :)