Android 4.0 隱藏虛擬按鍵(導覽列)的方法 .

來源:互聯網
上載者:User
在Android4.0裡,多了一些API,其中包括怎樣隱藏虛擬按鍵(導覽列),這樣編寫遊戲或一個視頻播放器時,可以設定隱藏虛擬按鍵的參數,達到最佳效果,當然前提是使用的手機是有虛擬按鍵的,例如galaxy nexus(i9250)。好吧,看一看官方的Android4.0 api說明就明白了。
 Controls for system UI visibility

Since the early days of Android, the system has managed a UI component known as the status bar, which resides at the top of handset devices to deliver information such as the carrier signal, time, notifications, and so on. Android 3.0 added the system
bar
 for tablet devices, which resides at the bottom of the screen to provide system navigation controls (Home, Back, and so forth) and also an interface for elements traditionally provided by the status bar. In Android 4.0, the system provides a new type
of system UI called the navigation bar. You might consider the navigation bar a re-tuned version of the system bar designed for handsets—it provides navigation controls for devices that don’t have hardware counterparts for navigating the system, but
it leaves out the system bar's notification UI and setting controls. As such, a device that provides the navigation bar also has the status bar at the top.

To this day, you can hide the status bar on handsets using the 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 flag replaces the STATUS_BAR_HIDDEN flag.
    When set, this flag en
    import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;public class HideTestActivity extends Activity implements OnClickListener{View main ;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        main = getLayoutInflater().from(this).inflate(R.layout.main, null);        main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);        main.setOnClickListener(this);        setContentView(main);    }@Overridepublic void onClick(View v) {int i = main.getSystemUiVisibility();if (i == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);} else if (i == View.SYSTEM_UI_FLAG_VISIBLE){main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);} else if (i == View.SYSTEM_UI_FLAG_LOW_PROFILE) {main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);}}}

    ables “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 flag replaces the STATUS_BAR_VISIBLE flag
    to request the system bar or navigation bar be visible.
  • The 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.

You can set each of these flags for the system bar and navigation bar by calling setSystemUiVisibility() on
any view in your activity. The window manager combines (OR-together) all flags from all views in your window and apply them to the system UI as long as your window has input focus. When your window loses input focus (the user navigates away from your app,
or a dialog appears), your flags cease to have effect. Similarly, if you remove those views from the view hierarchy their flags no longer apply.

To synchronize other events in your activity with visibility changes to the system UI (for example, hide the action bar or other UI controls when the system UI hides), you should register a View.OnSystemUiVisibilityChangeListener to
be notified when the visibility of the system bar or navigation bar changes.

See the OverscanActivity class for a demonstration of different system UI options.

看完後,寫個測試例子試一下,Ok~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.