开发者

How to use android styles in styles.xml in programmatic design of views

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:layou开发者_运维技巧t_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... :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜