作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在动态创建 8 个 TextView
并将它们添加到我的布局中。我想设置他们的文字颜色。所以我在 color.xml 中声明了颜色代码,并将其设置为:
txt1.setTextColor(getResources().getColor(R.color.off_white));
但我必须对所有 TextView
单独执行此操作。有没有一种方法可以为所有 TextView 全局设置它。例如,类似于我们在 jQuery 中可以做的事情:
$('input[type="text"]').css('color','white');
最佳答案
您可以为此使用自定义 TextView
。
如图所示:
MyTextView mTxt = new MyTextView(getApplicationContext()); //Use MyTextView instead of TextView where you want to apply color
mTxt.setText("Some text");
您的自定义类 MyTextView
类似于:
public class MyTextView extends TextView{
public MyTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.setTextColor(Color.GREEN); //change color as per your need here.
}
}
希望对您有所帮助。
关于android - 如何以编程方式为所有 TextView 设置文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26500873/
在 Rails 中,您可以使用嵌套路由为 has_one 和 has_many 关系创建 RESTful 路由。可以在 Rails Guides 上找到示例 请问有没有什么好的方法可以为habtm关系
我是一名优秀的程序员,十分优秀!