我正在开发一款使用AndEngine的游戏。

AndEngine具有“ BaseGameActivity”,Google Play游戏服务也具有。我不得不将BaseGameActivity从AndEngine重命名为AEBaseGameActivity,并将其作为父类BaseGameActivity而不是Activity。

但这给了我这个错误:

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
        at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
        at org.andengine.util.ActivityUtils.requestFullscreen(ActivityUtils.java:56)
        at org.andengine.ui.activity.AEBaseGameActivity.applyEngineOptions(AEBaseGameActivity.java:427)
        at org.andengine.ui.activity.AEBaseGameActivity.onCreate(AEBaseGameActivity.java:83)


现在,AndEngine拥有以下代码:

public static void requestFullscreen(final Activity pActivity) {
        final Window window = pActivity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        window.requestFeature(Window.FEATURE_NO_TITLE);
    }


如果我对requestFeature行进行注释,则我的项目将运行!但是它的标题栏很丑。

有谁请知道解决办法?

编辑,这里有更多代码:

PS:AEBaseGameActivity.php扩展了BaseActivity,后者扩展了BaseGameActivity(以前只是活动)

AEBaseGameActivity.php

public abstract class AEBaseGameActivity extends BaseActivity implements IGameInterface, IRendererListener {
    @Override
    protected void onCreate(final Bundle pSavedInstanceState) {
        if(BuildConfig.DEBUG) {
            Debug.d(this.getClass().getSimpleName() + ".onCreate" + " @(Thread: '" + Thread.currentThread().getName() + "')");
        }

        super.onCreate(pSavedInstanceState);

        this.mGamePaused = true;

        this.mEngine = this.onCreateEngine(this.onCreateEngineOptions());
        this.mEngine.startUpdateThread();

        this.applyEngineOptions(); //REQUEST FULLSCREEN

        this.onSetContentView(); //SET CONTENT VIEW
    }

    ...

    private void applyEngineOptions() {
        final EngineOptions engineOptions = this.mEngine.getEngineOptions();

        if(engineOptions.isFullscreen()) {
            ActivityUtils.requestFullscreen(this); //ACTIVITY UTIL SHOWN LATER
        }

        ...
    }

    ...

    protected void onSetContentView() {
        this.mRenderSurfaceView = new RenderSurfaceView(this);
        this.mRenderSurfaceView.setRenderer(this.mEngine, this);

        this.setContentView(this.mRenderSurfaceView, AEBaseGameActivity.createSurfaceViewLayoutParams());
    }
}


ActivityUtils.java

public class ActivityUtils {

    public static void requestFullscreen(final Activity pActivity) {
        final Window window = pActivity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        window.requestFeature(Window.FEATURE_NO_TITLE); //IF COMMENTING THIS, THE GAME IS RUNNING
    }

    ...

}


编辑2:

该代码基本上只是AndEngine,这是原始代码:

https://github.com/nicolasgramlich/AndEngine/tree/GLES2/src/org/andengine/ui/activity

我的变更:


将BaseGameActivity重命名为AEBaseGameActivity
BaseActivity扩展了BaseGameActivity(来自Google Play游戏服务)而不是Activity
来自Google Play游戏服务的BaseGameUtils的BaseGameActivity和GameHelper.java。

最佳答案

好的,这就是我所做的:


我注释掉了导致问题的行(AndEngine的ActivityUtils.java第56行)
我在活动中将此添加到了Android清单中:

android:theme =“ @ android:style / Theme.NoTitleBar”


最终看起来像:

<activity
                android:name=".GameActivity"
                android:theme="@android:style/Theme.NoTitleBar"
                android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

08-17 19:33