将样式应用于动态创建的textViews

时间:2011-12-05 20:08:54

标签: android

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="detaileventTitle">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#000000</item>
        <item name="android:textSize">14dp</item>
        <item name="android:textStyle">bold</item>
    </style>

</resources>

我有通常在我的textview xml中添加style =“@ style / detaileventTitle”的风格。但是,我的文本视图是动态创建的。如何将此样式应用于textviews?

1 个答案:

答案 0 :(得分:0)

这有用吗:

    listParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
    LayoutParams.WRAP_CONTENT);

    listParams.addRule(RelativeLayout.BELOW, R.id.param_table);


    notConnTextView = new TextView(this);
    notConnTextView.setGravity(0x01); //center message
    notConnTextView.setTextColor(Color.WHITE);
    notConnTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 40); //not resolution aware
    notConnTextView.setText("Not Connected!");

    mainLayout.addView(notConnTextView, listParams);
相关问题