我希望能够在我的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="#ffffff"

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

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

到你的活动标签。

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

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

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

android:background="@color/white"

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

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

编辑:2012年11月18日

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

例如:

我希望能够改变背景颜色为白色在我的 最简单的Android应用程序。

题目说的是最简单的方法,所以在这里。

在所有父视图中设置parentViewStyle。像大多数家长视图你的活动,片段和对话框。

<LinearLayout style="@style/parentViewStyle">

  ... other components inside

</LinearLayout>

把这个样式放在res>values>styles.xml中

<style name="parentViewStyle">
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:background">@color/white</item> // set your color here.
    <item name="android:orientation">vertical</item>
</style>

通过这种方式,你不需要在未来改变背景颜色很多次。

访问Activity_Main.xml 有设计视图/和文本视图。 选择文本视图 编写如下代码: android:背景= " @color / colorAccent”

简单的方法

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

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