我有一个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);
}
}
}
但是当我显示PopupWindow
或Dialog
时,导航栏会再次出现。
我试过这个
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()
它时,导航栏将在那里。
如何在整个应用程序中永久隐藏导航栏?
答案 0 :(得分: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 Colorpublic 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);
}
}