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


当前回答

change_color setBackground getDrawable (R .[。purple_700);

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

其他回答

有时,文本与背景颜色相同,尝试用android:background="#CCCCCC"进入listview属性,你会看到。

我希望能够改变背景颜色为白色在我的 最简单的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>

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

简单的方法

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

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

不仅仅是给Kotlin,当你写作的时候

@color /

你可以选择任何你想要的,快速而简单:

android:background="@color/md_blue_900"

以最简单的方式通过编程改变背景颜色(仅不改变XML):

LinearLayout bgElement = (LinearLayout) findViewById(R.id.container);
bgElement.setBackgroundColor(Color.WHITE);

唯一的要求是activity_whatever.xml中的“base”元素有一个你可以在Java中引用的id(在这种情况下是容器):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/container"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
     ...
</LinearLayout>

Paschalis和James,谁在这里回答,有点引导我到这个解决方案,在检查了各种可能性如何设置TextView的文本颜色在代码?。

希望它能帮助到一些人!