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


当前回答

如果你想为整个活动添加背景色

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1de9b6"
    tools:context="com.example.abc.myapplication.MainActivity">
 </RelativeLayout>

如果你想使用背景视图

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Andrios"
    android:background="@color/colorAccent" />

希望这能有所帮助!

其他回答

你需要使用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 " / >

谢谢!

change_color setBackground getDrawable (R .[。purple_700);

当我尝试在点击时改变颜色时,这种方法是有效的。

你可以尝试在xml表:

android:background="@color/background_color"

如果你想为整个活动添加背景色

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1de9b6"
    tools:context="com.example.abc.myapplication.MainActivity">
 </RelativeLayout>

如果你想使用背景视图

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Andrios"
    android:background="@color/colorAccent" />

希望这能有所帮助!