0

我的 Android 应用程序有问题。

我使用此代码隐藏导航栏。

public class Initer {
    public static void fullScreen(Window window) {
        if (Build.VERSION.SDK_INT >= 19) {
            View decor = window.getDecorView();
            fullScreen(decor);
        } else {
            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

    public static void fullScreen(View decor) {
        if (Build.VERSION.SDK_INT >= 19) {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |    
                    View.SYSTEM_UI_FLAG_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}

但是当我显示PopupWindowDialog出现时,导航栏会再次出现。

我试过这样做

PopupWindow popupWindow =new PopupWindow(getWindow().getContext());
View popupWindowView = LayoutInflater.from(getWindow().getContext()).
        inflate(R.layout.dialog_interval_insert, null);
Initer.fullScreen(popupWindowView);

...

popupWindow.showAsDropDown(button_start);

显示时隐藏导航栏PopupWindow。但它不起作用。当我调用 时PopupWindow,导航栏将显示然后再次隐藏。当我dismiss()这样做时,导航栏就会出现。

如何在整个应用程序中永久隐藏导航栏?

4

1 回答 1

1

你可以使用这个代码

public void FullScreen_Activity(Activity activity) {
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

并更改 StatusBar 颜色

public void setStatusBarColor(Activity activity, int RecColor) {
        if (isApi21()) {
            Window window = activity.getWindow();
            // clear FLAG_TRANSLUCENT_STATUS flag:
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            // finally change the color
            window.setStatusBarColor(ContextCompat.getColor(activity, RecColor));
        }
    }

以及如何使用 FullScreen_Activity 方法

public class SplashActivity extends AppCompatActivity {
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getMethod().FullScreen_Activity(this);
    setContentView(R.layout.activity_splash);
    }
}
于 2018-03-24T08:24:10.323 回答