android - 用背景色写在android中

标签 android textview background-color

我是 android 开发的新手,我正在尝试用我在 main.xml 文件中设置的背景颜色编写一些东西/ 我的写代码是这样的

TextView textView = new TextView(this);
textView.setText(s);
setContentView(textView);

当我运行程序时,“setContentView”会覆盖背景颜色,是否有另一种书写方式不会覆盖 main.xml 文件中的内容?

最佳答案

您应该在 XML 文件中包含 TextView,然后像这样引用您的 TextView

TextView textView = (TextView)findViewById(R.id.id_of_your_textview);

关于android - 用背景色写在android中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7861430/

相关文章:

android - 如何在布局中将 TextView 居中?

android - 如何以编程方式更改 TextView 的图标?

python - 如何更改使用 Tkinter 完成的文本框的背景颜色和文本颜色?

xaml - 将 StackPanel 背景设置为 WP7 选定的强调(主题)颜色

带有动画的 Android startActivity

php - Android MySQL Php 应用程序尝试在 php 中使用 post 语句存储用户详细信息

单击时Android textView消失

android - 如何更改应用程序图标的背景颜色

android - 使用 RecyclerView 绑定(bind)数据

android - 应用程序内购买不起作用 : item not available for purchase