我需要在運行時切換到全屏模式(播放器應用程序),並返回到用戶點擊,所以它應該隱藏android系統欄(頂部)和後面,應用程序,菜單軟件按鈕面板(底部)。如何隱藏Android系統按鈕面板?
如何隱藏底部面板與軟件按鈕?
PS。我已經使用getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
,但它並不能幫助:
我需要在運行時切換到全屏模式(播放器應用程序),並返回到用戶點擊,所以它應該隱藏android系統欄(頂部)和後面,應用程序,菜單軟件按鈕面板(底部)。如何隱藏Android系統按鈕面板?
如何隱藏底部面板與軟件按鈕?
PS。我已經使用getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
,但它並不能幫助:
請參考官方文檔。
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
請參閱http://developer.android.com/training/system-ui/navigation.html和http://developer.android.com/training/system-ui/visibility.html
還需要添加IMMERSIVE標誌 – 4ntoine
使用Immersive Full-Screen Mode
似乎也不錯。
此外,還有是如何做到這一點的例子:http://developer.android.com/samples/ImmersiveMode/project.html
並檢查該Fragment
:http://developer.android.com/samples/ImmersiveMode/src/com.example.android.immersivemode/ImmersiveModeFragment.html
他們使用:decorView = getActivity().getWindow().getDecorView();
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final View decorView = getActivity().getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int i) {
int height = decorView.getHeight();
Log.i(TAG, "Current height: " + height);
}
});
在這裏你可以看到它適用於不同的版本(API):
/**
* Detects and toggles immersive mode (also known as "hidey bar" mode).
*/
public void toggleHideyBar() {
// The UI options currently enabled are represented by a bitfield.
// getSystemUiVisibility() gives us that bitfield.
int uiOptions = getActivity().getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
boolean isImmersiveModeEnabled =
((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
if (isImmersiveModeEnabled) {
Log.i(TAG, "Turning immersive mode mode off. ");
} else {
Log.i(TAG, "Turning immersive mode mode on.");
}
// Navigation bar hiding: Backwards compatible to ICS.
if (Build.VERSION.SDK_INT >= 14) {
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
// Status bar hiding: Backwards compatible to Jellybean
if (Build.VERSION.SDK_INT >= 16) {
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
}
// Immersive mode: Backward compatible to KitKat.
// Note that this flag doesn't do anything by itself, it only augments the behavior
// of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of this sample
// all three flags are being toggled together.
// Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
// Sticky immersive mode differs in that it makes the navigation and status bars
// semi-transparent, and the UI flag does not get cleared when the user interacts with
// the screen.
if (Build.VERSION.SDK_INT >= 18) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
like [this](http://developer.android.com/intl/es/training/system-ui/immersive.html)? – Blackbelt
似乎是我需要的,我要去嘗試它 – 4ntoine
不,使用'View.SYSTEM_UI_FLAG_FULLSCREEN'不隱藏軟件按鈕面板 – 4ntoine