android - TextViewCompat.setTextAppearance 不起作用
问题描述
我正在TextView
动态构建我的,我一直在尝试使用添加样式,TextViewCompat.setTextAppearance
但没有任何改变。
我还尝试更改 thecolor
或 thesize
以TextView
查看是否有任何更改但没有结果。
这是代码的一部分:
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);
解决方案
尝试这个:
TextView myTextView= findViewById(R.id.txt1);
myTextView.setTextAppearance(this, R.style.yourStyle);
(setTextAppearance的第一个参数是上下文)
推荐阅读
- ios - UIButton 文本在更新为新文本之前闪烁“旧”文本
- makefile - 比较 Makefile 中两个文件的名称
- r - R中的概率回归
- azure - 是否可以在 Azure B2C 中使用登录用户流后立即运行密码重置用户流?
- python - “NoneType”对象没有“编码”属性和 SMTP 334 错误
- python - 如何在 postgres 中强制 sqalchemy 浮点类型为实数
- python - 尝试在 Sagemaker 笔记本实例中进行预测时,Sagemaker 端点返回错误
- angular - Httpheaders 又该怎么办?
- python - pandas `isin()` 函数对 pd.date_range 和 datetime 类型的奇怪行为
- html - CSS:如何选择元素内的标签?