gpt4 book ai didi

android - 如何使用系统覆盖窗口隐藏导航栏

转载 作者:太空狗 更新时间:2023-10-29 16:00:57 26 4
gpt4 key购买 nike

LockScreenReceiver.java

public class LockScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

//If the screen was just turned on or it just booted up, start your Lock Activity
if(action.equals(Intent.ACTION_SCREEN_OFF) || action.equals(Intent.ACTION_BOOT_COMPLETED))
{

//Create a window manager params
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
//makeFullScreen((Activity) context);

WindowManager wm = (WindowManager) context.getSystemService(context.WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);

final View myView = inflater.inflate(R.layout.my_view, null);

myView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("TAG", "touch me");
myView.setVisibility(View.GONE);
return true;
}
});

// Add layout to window manager
wm.addView(myView, params);
}
}

}

我有什么: 我有如下所示的输出,这是点击它时的 View ,它的可见性消失了

enter image description here


我正在尝试做的事情:我想在加载上述 View 时隐藏具有后退和中心按钮的栏。


如何实现?

最佳答案

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.format = PixelFormat.RGBA_8888;
lp.flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_FULLSCREEN;
lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;

int flag = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

mRootView.setSystemUiVisibility(flag);
mWindowManager.addView(mRootView, getLayoutParams());

不要使用WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,这个标志会让导航栏一直显示。我不知道为什么。

关于android - 如何使用系统覆盖窗口隐藏导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33386897/

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