【发布时间】:2012-07-19 18:03:43
【问题描述】:
我试图将大多数实用程序函数抽象化,因此我决定将它们分离到一个名为 Utils.java 的新类中(在 Android 应用程序包中)。
但是,我很难将活动上下文传递给这个助手类并在其(助手类的方法)中运行一些系统内容。
我在主要活动的 onCreate 中有这个场景:
Utils u = new Utils(this);
u.makeFullscreen();
Utils.java:
package mypackagenamehere;
import android.content.Context;
import android.view.Window;
import android.view.WindowManager;
public class Utils{
Context context;
// Constructor
public Utils(Context c) {
context = c;
}
public void makeFullscreen(){
context.requestWindowFeature(Window.FEATURE_NO_TITLE);
context.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
问题在于 makeFullscreen() 方法的内容。
【问题讨论】:
-
确保你在
setContentView之前调用了makeFullscreen,因为这是必须的要求。因为你在那个方法中调用requestWindowFeature。