1

我正在制作一个应用程序,当手机处于 PORTRAIT 方向时,我需要片段显示菜单栏(带有设置快捷方式等),但是当它处于 LANDSCAPE 中时,我需要全屏。

所以,我有一个管理 2 个片段的活动,如果它在 PORTRAIT 中,则调用 Fragment 1,如果在 LANDSCAPE 中,则调用 Fragment 2。只有片段 2 需要全屏显示。

可能吗?

4

2 回答 2

3

您不需要 2 个片段。只需添加android:configChanges="orientation|screenSize"到清单文件中的活动并将以下内容添加到活动中:

private int oldOptions;

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
        oldOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newOptions = oldOptions;
        newOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
        newOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
        newOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        newOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
        newOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        getWindow().getDecorView().setSystemUiVisibility(newOptions);
        getActionBar().hide();
    }
    else
    {
        getWindow().getDecorView().setSystemUiVisibility(oldOptions);
        getActionBar().show();
    }
}
于 2014-05-01T22:29:04.763 回答
0

您需要覆盖onConfigurationChanged和管理中的操作栏Activity

@Override
public void onConfigurationChanged(Configuration newConfig) {

    super.onConfigurationChanged(newConfig);
    if(newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
        getActionBar().show();
    }
    else {
        getActionBar().hide();
    }
}

也在configChanges清单中为此设置Activity

 android:configChanges="orientation|screenSize"
于 2014-05-01T22:30:26.027 回答