2016-05-19 247 views
1

我想隐藏导航栏(所有屏幕)在我的应用程序。下面的代码隐藏导航栏。但如果我再次点击编辑文本导航栏出现。如何隐藏?隐藏导航栏

@Override 
protected void onCreate(Bundle savedInstanceState) { 
View decorView = getWindow().getDecorView(); 
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { 
     @Override 
     public void onSystemUiVisibilityChange(int visibility) { 
      if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { 
       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); 
      } 
     } 
    }); 
} 

回答

0

您可以通过以下清单中的代码行的应用程序标记

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 

你试图做什么是屏幕的沉浸式模式。显示用户交互导航栏的位置。

-1

从我的问题可以理解,你希望你的应用程序删除`ActionBar'并完全全屏。如果是这样的话,你会想要做两个特别的事情,这取决于你的应用程序的目标版本:

如果> 4.1:

View decorView = getWindow().getDecorView(); 
// Hide the status bar 
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
decorView.setSystemUiVisibility(uiOptions); 
// Remember that you should never show the action bar if the 
// status bar is hidden, so hide that too if necessary. 
ActionBar actionBar = getActionBar(); 
actionBar.hide(); 

不然,如果< 4.1:

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     // If the Android version is lower than Jellybean, use this call to hide 
     // the status bar 
     if (Build.VERSION.SDK_INT < 16) { 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     } 
     setContentView(R.layout.activity_main); 
    } 
} 

请让我知道这是否解决了您的问题。如果没有,我们可以确定究竟是哪里出了问题,并从那里拿走。我希望这有帮助。

0

AndroidManifest.xml

<activity 
     android:name=".MainActivity" 
     android:label="@string/title_activity_main" 
     android:theme="@style/AppTheme.NoActionBar" /> 

只需使用其中@style/AppTheme.NoActionBarstyle.xml

<style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 
-2
View decorView = getWindow().getDecorView(); 
    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
      | View.SYSTEM_UI_FLAG_FULLSCREEN; 
    decorView.setSystemUiVisibility(uiOptions); 
+0

FYI这是从文档的码:https://developer.android.com/training/system -ui/navigation.html。 @Rob将一些评论添加到您复制的代码中会很棒。 – Micer