gpt4 book ai didi

android - 自上而下滑动时阻止状态栏

转载 作者:太空狗 更新时间:2023-10-29 14:12:17 28 4
gpt4 key购买 nike

我有一个覆盖整个屏幕的全屏应用程序,包括顶部状态栏。由于启用了向上/向下滑动以向用户显示一些选项,因此从上到下滑动会显示状态栏(当您想查看通知并从上向下滑动时) .有没有办法避免这种情况?

最佳答案

为 WindowManager.LayoutParams 使用类型 TYPE_SYSTEM_ERROR,以创建隐藏不可能的全屏 View 。显示状态栏和导航的滑动将被阻止。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mMainLayout = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.activity_fullscreen, null);

requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

WindowManager.LayoutParams handleParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
handleParams.gravity = Gravity.TOP;

WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(mMainLayout, handleParams);
}

如果需要,您应该在显示器开机(解锁屏幕)后显示它。添加代码:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

关于android - 自上而下滑动时阻止状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26334886/

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