gpt4 book ai didi

android - 全屏 fragment

转载 作者:行者123 更新时间:2023-11-29 17:50:11 48 4
gpt4 key购买 nike

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

因此,我有一个管理 2 个 fragment 的 Activity ,如果它是纵向的,则调用 fragment 1,如果是横向的,则调用 fragment 2。只有 Fragment 2 需要全屏显示。

这可能吗?

最佳答案

您不需要 2 个 fragment 。只需将 android:configChanges="orientation|screenSize" 添加到 list 文件中的 Activity ,并将以下内容添加到 Activity 中:

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();
}
}

关于android - 全屏 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23417614/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com