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

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

问题描述

我想改变我的主视野的背景颜色(而不是一个按钮或文本视图),只是现实背景通常是黑色的......我得到这个code:

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

view.setBackgroundColor(0xfff00000);

这是内部的OnClickListener,但它只是改变了按钮的背景......请帮助我,非常感谢!

This is inside an OnClickListener, but it just changes the background of the Button... Please help me, thanks a lot!

推荐答案

尝试建立在你的活动的方法类似...

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.

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

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