[英]non-static method getHostServices() cannot be referenced from a static context
[英]setBackground(): non-static method cannot be referenced from a static context
我想更改 FrameLayout 的背景。 这是我现在使用的代码:
FrameLayout.setBackground(getResources().getDrawable(R.drawable.background));
但是出现这个错误:
不能从静态上下文中引用非静态方法“setBackground(android.graphics.drawable.Drawable)”。
有什么问题吗?
FrameLayout
是一个类。 当您调用FrameLayout.setBackground()
您试图在 FrameLayout 类本身上调用一个名为setBackground()
的静态方法。 这个错误告诉你这样的静态方法不存在。
您真正想要做的是在 FrameLayout 的特定实例上调用setBackground()
方法。
首先,您需要获取对 FrameLayout 的引用(通常通过调用findViewById()
,然后调用setBackground()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.