我希望能够在我的android应用程序中以最简单的方式将背景颜色更改为白色。


当前回答

在布局中,改变背景使用这个。

android:background="@color/your_color"

在程序中可以使用这个。例如:Texview背景色

 TextView tvName = (TextView) findViewById(R.id.tvName);
 tvName.setBackgroundColor(getResources().getColor(R.color.your_color));

其他回答

你需要使用android:background属性,例如

android:background="@color/white"

此外,您还需要在strings.xml中为white添加一个值

<color name="white">#FFFFFF</color>

编辑:2012年11月18日

8字母颜色代码的前两个字母提供alpha值,如果你使用html 6字母颜色符号,颜色是不透明的。

例如:

android:背景= " # 64 b5f6 " 您可以根据自己的规范或需要更改'#'后的值,这取决于您想如何使用它们。 下面是一个示例代码:

< TextView android:文本= " Abir " android: layout_width = " match_parent " android: layout_height = " wrap_content " android: textSize = " 24 sp " android:背景= " # D4E157 " / >

谢谢!

你可以试试这种方法

android:background="@color/white"

你也可以使用

android:background="#ffffff"

在你的xml布局或/res/layout/activity_main.xml中,或者你可以在你的AndroidManifest.xml中通过添加

android:theme="@android:style/Theme.Light"

到你的活动标签。

如果您想动态更改背景,请使用

YourView.setBackgroundColor(Color.argb(255, 255, 255, 255));

你可以尝试在xml表:

android:background="@color/background_color"