Android 4.0 因为项目需要, 要实现屏幕全屏,隐藏虚拟按键,即导航栏

在Android的API 中

To this day, you can hide the status bar on handsets using the [FLAG_FULLSCREEN](http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN) flag. In Android 4.0, the APIs that control the system bar’s visibility have been updated to better reflect the behavior of both the system bar and navigation bar:

  • The [SYSTEM_UI_FLAG_LOW_PROFILE](http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_LOW_PROFILE) flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile” mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.
  • The [SYSTEM_UI_FLAG_VISIBLE](http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_VISIBLE) flag replaces the STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.
  • The [SYSTEM_UI_FLAG_HIDE_NAVIGATION](http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_HIDE_NAVIGATION) is a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets). The navigation bar returns to view as soon as the system receives user input. As such, this mode is useful primarily for video playback or other cases in which the whole screen is needed but user input is not required
 `<a href="http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_LOW_PROFILE" target="_blank">SYSTEM_UI_FLAG_LOW_PROFILE</a> 相当于隐藏导航栏`
 [SYSTEM_UI_FLAG_VISIBLE](http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_VISIBLE)         导航栏显示
 `<a href="http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_HIDE_NAVIGATION" target="_blank">SYSTEM_UI_FLAG_HIDE_NAVIGATION</a>` 要求导航栏完全隐藏–>但这对部分硬件设备有效
方法一:
**[java]** [view plain](http://blog.csdn.net/windownew11/article/details/9427469#)[copy](http://blog.csdn.net/windownew11/article/details/9427469#)
  <div>
  </div>
  
  <div>
    <embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash" width="18" height="18" align="middle" name="ZeroClipboardMovie_1">
    </embed>
  </div>
</div>
- <span class="keyword">package</span> com.example.setbutton;

- 
- <span class="keyword">import</span> android.os.Bundle;

- <span class="keyword">import</span> android.app.Activity;

- <span class="keyword">import</span> android.view.View;

- <span class="keyword">import</span> android.view.Window;

- <span class="keyword">import</span> android.view.WindowManager;

- <span class="keyword">public</span> <span class="keyword">class</span> MainActivity <span class="keyword">extends</span> Activity {

- 
- Window window;

- 
- <span class="comment">/** Called when the activity is first created. */</span>

- <span class="annotation">@Override</span>

- <span class="keyword">public</span> <span class="keyword">void</span> onCreate(Bundle savedInstanceState) {

- <span class="keyword">super</span>.onCreate(savedInstanceState);

- <span class="comment">// main = getLayoutInflater().from(this).inflate(R.layout.main, null);</span>

- window = getWindow();

- WindowManager.LayoutParams params = window.getAttributes();

- params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE;

- window.setAttributes(params);

- 
- setContentView(R.layout.main);

- }

- 
- }

 

方法二:

**[java]** [view plain](http://blog.csdn.net/windownew11/article/details/9427469#)[copy](http://blog.csdn.net/windownew11/article/details/9427469#)
  <div>
  </div>
  
  <div>
    <embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash" width="18" height="18" align="middle" name="ZeroClipboardMovie_2">
    </embed>
  </div>
</div>
- <span class="keyword">package</span> com.example.setbutton;

- 
- <span class="keyword">import</span> android.os.Bundle;

- <span class="keyword">import</span> android.app.Activity;

- <span class="keyword">import</span> android.view.View;

- <span class="keyword">import</span> android.view.View.OnClickListener;

- <span class="keyword">import</span> android.view.Window;

- <span class="keyword">import</span> android.view.WindowManager;

- <span class="keyword">import</span> android.widget.Button;

- 
- <span class="keyword">public</span> <span class="keyword">class</span> MainActivity <span class="keyword">extends</span> Activity {

- 
- View main;

- <span class="keyword">private</span> Button btn;

- 
- <span class="comment">/** Called when the activity is first created. */</span>

- <span class="annotation">@Override</span>

- <span class="keyword">public</span> <span class="keyword">void</span> onCreate(Bundle savedInstanceState) {

- <span class="keyword">super</span>.onCreate(savedInstanceState);

- main = getLayoutInflater().from(<span class="keyword">this</span>).inflate(R.layout.main, <span class="keyword">null</span>);

- 
- btn = (Button) main.findViewById(R.id.btn);

- btn.setOnClickListener(<span class="keyword">new</span> OnClickListener() {

- 
- <span class="annotation">@Override</span>

- <span class="keyword">public</span> <span class="keyword">void</span> onClick(View v) {

- <span class="comment">// TODO Auto-generated method stub</span>

- <span class="keyword">int</span> i = main.getSystemUiVisibility();

- 
- <span class="keyword">if</span> (i == View.SYSTEM_UI_FLAG_VISIBLE) {

- main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

- }

- }

- });

- 
- setContentView(main);

- 
- }

💬 评论