1
<?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>

I have the style above which I usually apply by adding style="@style/detaileventTitle" to my textview xml. However, my textviews are created dynamically. How do I apply this style to the textviews?

Adam
  • 8,849
  • 16
  • 67
  • 131
  • 2
    Duplicate question: http://stackoverflow.com/questions/4630440/how-to-change-a-textviews-style-at-runtime – John Giotta Dec 05 '11 at 20:25
  • Create a layout xml for the `TextView` on its own and apply the style in that. Then use `LayoutInfater` to inflate individual instances of the `TextView`. – Squonk Dec 05 '11 at 20:27

1 Answers1

0

Does this help:

    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);