【发布时间】:2013-01-15 16:39:38
【问题描述】:
我找到了this。所以,远没有运气。我使用了他的代码,但我无法克服这个错误。我不熟悉充气机。那么有人可以解释一下这段代码吗?
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup mTopView = (ViewGroup) getApplicationContext()
.getLayoutInflater().inflate(R.layout.activity_invisible, null);
getWindow().setAttributes(params);
wm.addView(mTopView, params);
这部分代码:
ViewGroup mTopView = (ViewGroup) getApplicationContext()
.getLayoutInflater().inflate(R.layout.activity_invisible, null);
给我这个错误The method getLayoutInflater() is undefined for the type Context
谁能解释我做错了什么?
【问题讨论】:
-
你在哪里尝试执行这段代码?
-
onCreate()方法本身。 -
可能是因为上下文中没有 getLayoutInflater() 方法。例如,尝试使用您的活动。或者,就像你在上面做的那样,getSystemService
-
我什至不明白,如果你不打算使用那个 layoutinflater,你为什么还要麻烦调用 getSystemService