我試圖使大部分實用函數抽象化,所以我決定將它們分成一個名爲Utils.java的新類(在Android應用程序包內部)。然而,我很難將活動上下文傳遞給這個輔助類,並在其輔助類的方法中運行一些系統的東西。通過傳遞活動上下文在外部類中的requestWindowFeature()
我有這種情況的主要活動的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()方法的內容。
確保你已經叫'makeFullscreen'之前'setContentView',因爲它是必須要求。你在這個方法中調用'requestWindowFeature'。 – 2012-07-19 19:05:58