Android:更改活动的背景颜色(主视图) [英] Android: Changing Background-Color of the Activity (Main View)

查看:21
本文介绍了Android:更改活动的背景颜色(主视图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的主视图(不是按钮或文本视图)的背景颜色,只是通常是黑色的真实背景......我得到了这个代码:

I want to change the background color of my Main-View (not a Button or a Text-View) just the real background which is usually black... I got this code:

view.setBackgroundColor(0xfff00000);

这是在 OnClickListener 中,但它只是改变了 Button 的背景.

This is inside an OnClickListener, but it just changes the background of the Button.

推荐答案

尝试在您的 Activity 中创建一个方法,例如...

Try creating a method in your Activity something like...

public void setActivityBackgroundColor(int color) {
    View view = this.getWindow().getDecorView();
    view.setBackgroundColor(color);
}

然后从您的 OnClickListener 中调用它并传入您想要的任何颜色.

Then call it from your OnClickListener passing in whatever colour you want.

这篇关于Android:更改活动的背景颜色(主视图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆