首页 > 解决方案 > TextViewCompat.setTextAppearance 不起作用

问题描述

我正在TextView动态构建我的,我一直在尝试使用添加样式,TextViewCompat.setTextAppearance但没有任何改变。

我还尝试更改 thecolor或 thesizeTextView查看是否有任何更改但没有结果。

这是代码的一部分:

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

标签: androidandroid-styles

解决方案


尝试这个:

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

(setTextAppearance的第一个参数是上下文)


推荐阅读