4

是否可以像在全屏应用程序中一样隐藏通知栏,但允许用户从顶部拖动它?

4

3 回答 3

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

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.NAME_OF_YOUR_ACTIVITY);
    getSupportActionBar().hide();

将此代码放在您的 java 活动中并替换NAME_OF_YOUR_ACTIVITY,而不是全屏活动。

于 2017-10-06T15:09:59.217 回答
0

There is no as such SDK support for this, but you may be able to do it with a bit of workaround coding.

You can use the WindowManager to inject an opaque floating View right at the top of the screen, which matches up with the rest of your layout and looks like a part of it.

Make sure your injected View is set to disregard touch events, and pass them down to whatever is below it. This should allow users to drag down the notification bar without actually keeping it visible on the screen. Well, it is still visible, just covered by your floating View.

Keep in mind that this will require your Activity theme to not be fullscreeen.

于 2013-05-26T23:15:49.297 回答
0

是的,只需将以下代码放入您的活动中即可。

 @Override
 public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    View view = getWindow().getDecorView();
    if (hasFocus) {
        view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        );

    }
}

在我的自定义相机应用程序之一中,我使用了它,它显示全屏相机视图,没有通知栏,当您从顶部拖动时,它会显示给您。
快乐编码... :)

于 2017-10-06T15:35:06.913 回答