簡體   English   中英

如何隱藏導航欄

[英]How to hide navigation bar

我在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()時,導航欄就會出現。

如何在整個應用程序中永久隱藏導航欄?

您可以使用此代碼

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

並使用更改狀態欄顏色

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM