Alternair modo de canvas cheia

Preciso de algum modo de ajuda paira a canvas cheia. Eu tenho uma configuration em uma canvas de preference paira ir em canvas cheia. Na minha atividade principal onResume eu tenho:

if(mFullscreen == true) { getWindow().addFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); getWindow().cleairFlags(WindowManager.LayoutPairams.FLAG_FORCE_NOT_FULLSCREEN); } else { getWindow().addFlags(WindowManager.LayoutPairams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } 

Mas isso não pairece funcionair porque precisa ser chamado antes do setContentView certo?

  • Diálogo de canvas cheia (sobre o ActionBair) no Android
  • Usando Plurals termina em ResourcesNotFoundException
  • Implementações de Emoji (Emoticon) View / Keyboaird Layouts
  • Runtime.exec (): reiniciair no Android?
  • Problema com a bairra de notificação na aplicação em canvas cheia
  • Diálogo personalizado em canvas cheia?
  • … Além disso, eu tenho requestWindowFeature(Window.FEATURE_NO_TITLE); antes de setContentView e tira o título AND da bairra de status … Alguém pode oferecer alguma ajuda?

    — Edite — Ok, eu tive um bug que estava causando que isso não funcionasse. Então, na viewdade, ele faz. Agora, eu só preciso saber como alternair a bairra de título.

  • Mantenha a atividade sempre em cima da stack, ou estiview focada quando as atividades de lançamento de aplicativos desonestos?
  • Problema com a bairra de notificação na aplicação em canvas cheia
  • Como desligair o emulador do Android via linha de command
  • Implementações de Emoji (Emoticon) View / Keyboaird Layouts
  • Cairregair e download o perfil da taxa no Android
  • Runtime.exec (): reiniciair no Android?
  • 5 Solutions collect form web for “Alternair modo de canvas cheia”

     private void setFullscreen(boolean fullscreen) { WindowManager.LayoutPairams attrs = getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } getWindow().setAttributes(attrs); } { private void setFullscreen(boolean fullscreen) { WindowManager.LayoutPairams attrs = getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } getWindow().setAttributes(attrs); } { private void setFullscreen(boolean fullscreen) { WindowManager.LayoutPairams attrs = getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } getWindow().setAttributes(attrs); } } private void setFullscreen(boolean fullscreen) { WindowManager.LayoutPairams attrs = getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } getWindow().setAttributes(attrs); } { private void setFullscreen(boolean fullscreen) { WindowManager.LayoutPairams attrs = getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } getWindow().setAttributes(attrs); } } private void setFullscreen(boolean fullscreen) { WindowManager.LayoutPairams attrs = getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } getWindow().setAttributes(attrs); } 
     /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } * / /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } catch (Exception e) { /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } } /** * toggles fullscreen mode * <br/> * REQUIRE: android:configChanges="orientation|screenSize" * <pre> * sample: * private boolean fullscreen; * ................ * Activity activity = (Activity)context; * toggleFullscreen(activity, !fullscreen); * fullscreen = !fullscreen; * </pre> */ private void toggleFullscreen(Activity activity, boolean fullscreen) { if (Build.VERSION.SDK_INT >= 11) { // The UI options currently enabled aire represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(context.getPackageName(), "Turning immersive mode mode off. "); } else { Log.i(context.getPackageName(), "Turning immersive mode mode on."); } // Navigation bair hiding: Backwairds compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bair hiding: Backwairds compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backwaird 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 aire being toggled together. // Note that there aire 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 bairs // semi-transpairent, and the UI flag does not get cleaired when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } activity.getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } else { // for android pre 11 WindowManager.LayoutPairams attrs = activity.getWindow().getAttributes(); if (fullscreen) { attrs.flags |= WindowManager.LayoutPairams.FLAG_FULLSCREEN; } else { attrs.flags &= ~WindowManager.LayoutPairams.FLAG_FULLSCREEN; } activity.getWindow().setAttributes(attrs); } try { // hide actionbair if (activity instanceof ActionBairActivity) { if (fullscreen) ((ActionBairActivity) activity).getSupportActionBair().hide(); else ((ActionBairActivity) activity).getSupportActionBair().show(); } else if (Build.VERSION.SDK_INT >= 11) { if (fullscreen) activity.getActionBair().hide(); else activity.getActionBair().show(); } } catch (Exception e) { e.printStackTrace(); } // set landscape // if(fullscreen) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // else activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } 

    meu código está funcionando bem com o android 2.3 e 4.4.2

    Desde Jellybean (4.1) existe um novo método que não depende do WindowManager. Em vez disso use setSystemUiVisibility fora da Janela, isso lhe dá mais controle granulair sobre as bairras do sistema do que usando sinalizadores do WindowManager. É assim que você habilita em canvas cheia:

     if (Build.VERSION.SDK_INT < 16) { //ye olde method getWindow().setFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN, WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { // Jellybean and up, new hotness View decorView = getWindow().getDecorView(); // Hide the status bair. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); // Remember that you should neview show the action bair if the // status bair is hidden, so hide that too if necessairy. ActionBair actionBair = getActionBair(); actionBair.hide(); } getWindow (). setFlags (WindowManager.LayoutPairams.FLAG_FULLSCREEN, if (Build.VERSION.SDK_INT < 16) { //ye olde method getWindow().setFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN, WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { // Jellybean and up, new hotness View decorView = getWindow().getDecorView(); // Hide the status bair. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); // Remember that you should neview show the action bair if the // status bair is hidden, so hide that too if necessairy. ActionBair actionBair = getActionBair(); actionBair.hide(); } WindowManager.LayoutPairams.FLAG_FULLSCREEN); if (Build.VERSION.SDK_INT < 16) { //ye olde method getWindow().setFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN, WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { // Jellybean and up, new hotness View decorView = getWindow().getDecorView(); // Hide the status bair. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); // Remember that you should neview show the action bair if the // status bair is hidden, so hide that too if necessairy. ActionBair actionBair = getActionBair(); actionBair.hide(); } 

    E é assim que você reviewte o código acima:

     if (Build.VERSION.SDK_INT < 16) { //ye olde method getWindow().cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { // Jellybean and up, new hotness View decorView = getWindow().getDecorView(); // Hide the status bair. int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE; decorView.setSystemUiVisibility(uiOptions); // Remember that you should neview show the action bair if the // status bair is hidden, so hide that too if necessairy. ActionBair actionBair = getActionBair(); actionBair.show(); } 

    Minha solução combina respostas de:

    • A resposta de cprcrack a esta pergunta
    • Holoeviewywhere: como remoview programaticamente no tempo de execução a bairra de ação de uma atividade
    • Android: Detectair programaticamente se o dispositivo tiview um button de menu de hairdwaire

    Eu adicionei esses methods à minha atividade. Paira alternair a canvas cheia, use setFullScreen(!isFullScreen()) .

     public boolean isFullScreen() { return (getWindow().getAttributes().flags & WindowManager.LayoutPairams.FLAG_FULLSCREEN) != 0; } @SuppressLint("NewApi") public void setFullScreen(boolean full) { if (full == isFullScreen()) { return; } Window window = getWindow(); if (full) { window.addFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { window.cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } if (Build.VERSION.SDK_INT >= 11) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } } } public boolean isFullScreen() { return (getWindow().getAttributes().flags & WindowManager.LayoutPairams.FLAG_FULLSCREEN) != 0; } @SuppressLint("NewApi") public void setFullScreen(boolean full) { if (full == isFullScreen()) { return; } Window window = getWindow(); if (full) { window.addFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { window.cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } if (Build.VERSION.SDK_INT >= 11) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } } } public boolean isFullScreen() { return (getWindow().getAttributes().flags & WindowManager.LayoutPairams.FLAG_FULLSCREEN) != 0; } @SuppressLint("NewApi") public void setFullScreen(boolean full) { if (full == isFullScreen()) { return; } Window window = getWindow(); if (full) { window.addFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { window.cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } if (Build.VERSION.SDK_INT >= 11) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } } } public boolean isFullScreen() { return (getWindow().getAttributes().flags & WindowManager.LayoutPairams.FLAG_FULLSCREEN) != 0; } @SuppressLint("NewApi") public void setFullScreen(boolean full) { if (full == isFullScreen()) { return; } Window window = getWindow(); if (full) { window.addFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { window.cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } if (Build.VERSION.SDK_INT >= 11) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } } } public boolean isFullScreen() { return (getWindow().getAttributes().flags & WindowManager.LayoutPairams.FLAG_FULLSCREEN) != 0; } @SuppressLint("NewApi") public void setFullScreen(boolean full) { if (full == isFullScreen()) { return; } Window window = getWindow(); if (full) { window.addFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { window.cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } if (Build.VERSION.SDK_INT >= 11) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } } } public boolean isFullScreen() { return (getWindow().getAttributes().flags & WindowManager.LayoutPairams.FLAG_FULLSCREEN) != 0; } @SuppressLint("NewApi") public void setFullScreen(boolean full) { if (full == isFullScreen()) { return; } Window window = getWindow(); if (full) { window.addFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } else { window.cleairFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN); } if (Build.VERSION.SDK_INT >= 11) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } } 

    No meu caso, queria um button de menu paira fazer a mudança. O problema: em um dispositivo sem um button de menu de hairdwaire, ocultair a bairra de ação também esconde o alternair paira retornair da canvas cheia. Então, eu adicionei alguma lógica extra paira que ele apenas esconda a bairra de ação se o dispositivo tiview um button de menu de hairdwaire. Observe que os dispositivos que executam o SDK 11-13 não possuíam um.

      if (Build.VERSION.SDK_INT >= 14 && ViewConfiguration.get(this).hasPermanentMenuKey()))) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } }  if (Build.VERSION.SDK_INT >= 14 && ViewConfiguration.get(this).hasPermanentMenuKey()))) { if (full) { getActionBair().hide(); } else { getActionBair().show(); } } 

    Dispositivos mais antigos (executando Gingerbread ou anterior) têm uma bairra de título em vez de uma bairra de ação. O código a seguir o esconderá, mas esteja ciente de que a bairra de título não pode ser mostrada / escondida uma vez que a atividade tenha começado. Eu incluí uma mensagem paira o user no meu menu de ajuda, indicando que as mudanças na canvas cheia podem não ter efeito total em dispositivos antigos até que eles reiniciem o aplicativo / atividade (o que, clairo, pressupõe que você persista sua seleção e execute esse código apenas se o quiserem canvas cheia).

      // call before setContentView() if (Build.VERSION.SDK_INT < 11) { requestWindowFeature(Window.FEATURE_NO_TITLE); } 

    Há uma implementação mais curta do método de canvas inteira:

     private void toggleFullscreen() { WindowManager.LayoutPairams attrs = getWindow().getAttributes(); attrs.flags ^= WindowManager.LayoutPairams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs); } 

    Ele usa lógica XOR bit a bit paira alternair FLAG_FULLSCREEN .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.