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


当前回答

change_color setBackground getDrawable (R .[。purple_700);

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

其他回答

最简单的方法是在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>

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

<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="@color/your_color"

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

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

简单的方法

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

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

你也可以使用

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));