如何在Android应用中隐藏导航栏?

时间:2015-06-12 21:43:26

标签: android android-studio fullscreen navigationbar

我想知道如何隐藏Android应用程序中的导航栏?

我知道如何隐藏它,但是一触摸屏幕就会弹回来。我想隐藏它,就像Clash of Clans之类的游戏隐藏它一样,弹出它的唯一方法是向下滑动通知或者滑动导航栏应该在哪里。

7 个答案:

答案 0 :(得分:5)

使用沉浸式模式检查此Immersive mode

    // This snippet hides the system bars.
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

答案 1 :(得分:1)

这是在onCreate方法的上下文中:

dir.create(file.path(output.path, date))
library(RODBC)
conn <- odbcConnect("Azure", uid = "aaaaa", pwd = "aaaaa")
etldata <- sqlFetch(conn,"dbo.EtlLogsData", stringsAsFactors = FALSE)

pdf(paste('ETL_Duration_For_Effective_Date_', date,'.pdf',sep = ""),
  width = 12,
  height = 8,
  paper = 'special')

par(mar = c(5, 17, 5, 3))

plot(c(min(etldata_day$st_sec), max(etldata_day$et_sec)),
   c(sn[1], sn[1]),
   ylim = c(0, n),
   yaxt = 'n',
   xaxt = 'n',
   ylab = '',
   xlab = 'Time',
   main = paste('ETL Duration With Effective Date ', date, sep = ""))
   abline(h = sn, untf = FALSE, col = "gray90")

for (i in 1:n){
lines(c(etldata_day$st_sec[i], etldata_day$et_sec[i]),
      c(sn[i], sn[i]),
      type = "l", lwd = 2)
arrows(etldata_day$st_sec[i], sn[i],
       etldata_day$et_sec[i], sn[i],
       length = 0.025, angle = 90, lwd = 2)
arrows(etldata_day$et_sec[i], sn[i],
       etldata_day$st_sec[i], sn[i],
       length = 0.025, angle = 90, lwd = 2)
}

# Print y axis labels
axis(2, at = sn, labels = etldata_day$TaskName, las = 1, cex.axis = 1)

# Print x axis labels
xat <- seq(from = min(etldata_day$st_sec), to = max(etldata_day$et_sec),      length.out = 10)
xlabels <- secondsToString(xat)
axis(1, at = xat, labels = substr(xlabels,1,8), cex.axis = 1)
dev.off()

Android文档很好地解释了不同标志的作用: Using Immersive Full-Screen Mode

答案 2 :(得分:1)

简单的方法是在super.onCreate(savedInstanceState)之后添加这两行;

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

答案 3 :(得分:1)

只需将此方法放在您要在即时贴模式下隐藏状态栏和导航栏的活动中即可。

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    //This is used to hide/show 'Status Bar' & 'System Bar'. Swip bar to get it as visible.
    View decorView = getWindow().getDecorView();
    if (hasFocus) {
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}

答案 4 :(得分:0)

在您的活动中使用onCreate方法:

    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

答案 5 :(得分:0)

您可以使用上面的代码段创建活动,然后在布局上方添加另一个窗口:

LayoutParams layoutParameteres=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        v.setLayoutParams(layoutParameteres);
        final WindowManager.LayoutParams parameters=new WindowManager.LayoutParams(sizeX, sizeY, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
        parameters.gravity=Gravity.CENTER;
        parameters.x=0;
        parameters.y=0;
        wm.addView(v, parameters);

祝你好运

答案 6 :(得分:-1)

修改AndroidManifest.xml文件中的这一行

android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"