Sarah Omar
Sarah Omar

Reputation: 1

TextViewCompat.setTextAppearance is not working

I'm building my TextView dynamically and I've been trying to add a style using TextViewCompat.setTextAppearance but nothing is changing.

I've also tried to change the color or the size for the TextView to see if anything changes but with no results.

Here is a part of the code:

        LinearLayout frameLayout = new LinearLayout(SubmitBills.this);
        frameLayout.setOrientation(LinearLayout.HORIZONTAL);
        frameLayout.setPadding(0, 20, 0, 20);

        ImageView icon = new ImageView(SubmitBills.this);
        icon.setImageResource(R.drawable.img);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
        icon.setLayoutParams(params);

        LinearLayout dataLayout = new LinearLayout(SubmitBills.this);
        dataLayout.setOrientation(LinearLayout.VERTICAL);

        LinearLayout one = new LinearLayout(SubmitBills.this);
        one.setOrientation(LinearLayout.HORIZONTAL);

        ITextView billerLabel = new ITextView(SubmitBills.this);
        ITextView biller = new ITextView(SubmitBills.this);
        ITextView dueAmtLabel = new ITextView(SubmitBills.this);
        ITextView dueAmt = new ITextView(SubmitBills.this);

        billerLabel.setText(R.string.biller_label);
        biller.setText(billsDtList.get(i).getBillerDesc());
        dueAmtLabel.setText(R.string.dueAmount);
        dueAmt.setText(billsDtList.get(i).getDueAmount());

        billerLabel.setPadding(0, 0, 30, 0);
        biller.setPadding(0, 0, 30, 0);
        dueAmtLabel.setPadding(0, 0, 30, 0);
        dueAmt.setPadding(0, 0, 30, 0);

        TextViewCompat.setTextAppearance(billerLabel, R.style.darkTextStyleRegular);
        TextViewCompat.setTextAppearance(biller, R.style.darkTextStyleRegular);
        TextViewCompat.setTextAppearance(dueAmtLabel, R.style.darkTextStyleBold);
        TextViewCompat.setTextAppearance(dueAmt, R.style.darkTextStyleRegular);

        one.addView(billerLabel);
        one.addView(biller);
        one.addView(dueAmtLabel);
        one.addView(dueAmt);

        dataLayout.addView(one);

        frameLayout.addView(icon);
        frameLayout.addView(dataLayout);

        bills.addView(frameLayout);

Upvotes: 0

Views: 732

Answers (1)

Juan Sancho
Juan Sancho

Reputation: 321

Try this:

TextView myTextView= findViewById(R.id.txt1);
myTextView.setTextAppearance(this, R.style.yourStyle);

(The first parameter of setTextAppearance is the context)

Upvotes: 1

Related Questions