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


当前回答

你可以使用简单的颜色资源,通常在里面指定

res/values/colors.xml.

use

<color name="red">#ffff0000</color>

并通过android:background="@color/red"使用这个。这种颜色也可以用于其他任何地方,例如作为文本颜色。以同样的方式在XML中引用它,或者在代码中通过

getResources().getColor(R.color.red).

你也可以使用任何可绘制的资源作为背景,使用android:background="@drawable/mydrawable"(这意味着9patch drawables,正常位图,形状drawables, ..)。

其他回答

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

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

谢谢!

最简单的方法是在layout.xml或/res/layout/activity_main.xml的主节点中添加android:background="#FFFFFF":

<?xml version="1.0" encoding="utf-8"?>
   <TextView xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:padding="10dp"
       android:textSize="20sp" 
       android:background="#FFFFFF">
   </TextView>

简单的方法

安卓:背景=“@android:颜色/白色”

不需要定义任何东西。它使用android.R中预定义的颜色。

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

android:background="@color/your_color"

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

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

你可以尝试在xml表:

android:background="@color/background_color"