我想改变我的主视图(不是按钮或文本视图)的背景颜色只是真实的背景,它通常是黑色的…我得到了这样的代码:
view.setBackgroundColor(0xfff00000);
这是在一个OnClickListener
中,但它只是改变了按钮的背景。
发布于 2012-01-22 20:42:48
尝试在您的Activity
中创建一个方法,类似于...
public void setActivityBackgroundColor(int color) {
View view = this.getWindow().getDecorView();
view.setBackgroundColor(color);
}
然后从你的OnClickListener调用它,传入你想要的任何颜色。
发布于 2012-01-22 21:48:15
我不知道这是否是您问题的答案,但是您可以尝试像这样设置xml布局中的背景色。这很简单,它总是有效的。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="0xfff00000"
>
<TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
你还可以通过创建一个带有渐变的xml背景文件来对背景做更多花哨的事情,这些渐变很酷,而且是半透明的,并参考它以用于其他用途请参见下面的示例:
background.xml布局
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#f0000000"
android:endColor="#ff444444"
android:type="linear" />
</shape>
</item>
</selector>
你的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/background"
>
<TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
发布于 2014-02-15 20:09:22
只需在相应活动XML文件中添加下面一行代码:
android:background="@android:color/black"
这肯定会对你有帮助。
https://stackoverflow.com/questions/8961071
复制相似问题