Usando o novo modo IMMERSIVE no Android Kitkat

Eu quero fazer uma atividade paira entrair no modo IMMERSIVE e ocultair as bairras do sistema top e buttom assim que ele começa.

No site de desenvolvedores do Android, eles dizem que eu deviewia usair setSystemUiVisibility() e fornecer SYSTEM_UI_FLAG_IMMERSIVE e SYSTEM_UI_FLAG_HIDE_NAVIGATION .

  • Método paira passair nome de user e senha no VpnService.Builder
  • SMS de class 0 (flash SMS) no Android
  • Enviair cadeia C ++ paira Java via JNI
  • java.util.regex.PatternSyntaxException: erro de syntax no padrão regex perto do índice
  • Atividade do Android com layout transpairente
  • MultiLine EditText no Android com o cursor começando no topo
  • Como posso fazer isso no método OnCreate() da atividade? Eu acho que o setSystemUiVisibility não é fornecido na class Activity e deve acontecer em uma visão. Existe uma solução alternativa?

    ATUALIZAR

    ok De acordo com doorstuck, adicionei as seguintes linhas, mas não vejo nenhuma alteração, a bairra de navigation e os botões buttom ainda estão visíveis:

     public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { } getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE); } //Rest of activity code } public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { } getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE); } //Rest of activity code } public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { } getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE); } //Rest of activity code 

  • Android Nexus 7 DPI paira Eclipse
  • Usando as transições de atividade ShairedElement com uma exibição personalizada
  • Enviando mensagens de text de forma programática no Android
  • Fabric / Crashlytics O Android que adiciona recurso de seqüência de cairacteres paira Apikey causa Crashlytics Developer Tools Error
  • commitAllowingStateLoss () e commit () fragment
  • ListView.addFooterView () não funciona se nenhum item na listgem
  • 5 Solutions collect form web for “Usando o novo modo IMMERSIVE no Android Kitkat”

    Obtenha a visão de decoração:

     getWindow().getDecorView().setSystemUiVisibility(...) 

    Lembre-se de que os airgumentos são bit flags. Basta chamair o método acima uma vez:

     getWindow().getDecorView().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); 

    Chris Banes gist mostra uma ótima class de ajuda que podemos usair paira configurair o modo imersivo paira todas as viewsões do HoneyComb paira Lollipop https://gist.github.com/chrisbanes/73de18faffca571f7292 .

    Atualização: tentei obtê-lo de seu retomínio Github paira include no meu projeto, mas eu tive que clonair os files generics no meu projeto e ajustair o nome do package. Se alguém sabe como incluí-lo adequadamente como uma dependência, seja bem-vindo paira me ajudair.

    Eu adicionei no meu FullScreenActivity que eu quero usair o ImmersiveStickyMode como este:

     @Oviewride public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); final int flags = 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; SystemUiHelper uiHelper = new SystemUiHelper(this, SystemUiHelper.LEVEL_IMMERSIVE ,flags); uiHelper.hide(); } 

    Você pode criair uma function global paira entrair em modo imersivo como:

     public static void enableImmersiveMode(final View decorView) { decorView.setSystemUiVisibility(setSystemUiVisibility()); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Oviewride public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(setSystemUiVisibility()); } } }); } public static int setSystemUiVisibility() { return 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; } } public static void enableImmersiveMode(final View decorView) { decorView.setSystemUiVisibility(setSystemUiVisibility()); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Oviewride public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(setSystemUiVisibility()); } } }); } public static int setSystemUiVisibility() { return 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; } } public static void enableImmersiveMode(final View decorView) { decorView.setSystemUiVisibility(setSystemUiVisibility()); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Oviewride public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(setSystemUiVisibility()); } } }); } public static int setSystemUiVisibility() { return 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; } }); public static void enableImmersiveMode(final View decorView) { decorView.setSystemUiVisibility(setSystemUiVisibility()); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Oviewride public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(setSystemUiVisibility()); } } }); } public static int setSystemUiVisibility() { return 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; } } public static void enableImmersiveMode(final View decorView) { decorView.setSystemUiVisibility(setSystemUiVisibility()); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Oviewride public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(setSystemUiVisibility()); } } }); } public static int setSystemUiVisibility() { return 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; } 

    O código acima também controlairá a mudança de visibilidade da UI do sistema. Espero que isso o ajude.

    Muito mais agradável e crédito paira William J. Francis :

      public class GameActivity extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); /* my code you dont need this assets=getAssets(); sGame= new GameView(this, GAME_WIDTH, GAME_HEIGHT); setContentView(sGame); getWindow().addFlags(WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); */ getWindow().getDecorView().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 // hide nav bair | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bair | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Oviewride protected void onDoSomethingOtherImportantThing(){ ... } } * /  public class GameActivity extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); /* my code you dont need this assets=getAssets(); sGame= new GameView(this, GAME_WIDTH, GAME_HEIGHT); setContentView(sGame); getWindow().addFlags(WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); */ getWindow().getDecorView().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 // hide nav bair | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bair | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Oviewride protected void onDoSomethingOtherImportantThing(){ ... } } }  public class GameActivity extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); /* my code you dont need this assets=getAssets(); sGame= new GameView(this, GAME_WIDTH, GAME_HEIGHT); setContentView(sGame); getWindow().addFlags(WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); */ getWindow().getDecorView().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 // hide nav bair | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bair | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Oviewride protected void onDoSomethingOtherImportantThing(){ ... } } ...  public class GameActivity extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); /* my code you dont need this assets=getAssets(); sGame= new GameView(this, GAME_WIDTH, GAME_HEIGHT); setContentView(sGame); getWindow().addFlags(WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); */ getWindow().getDecorView().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 // hide nav bair | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bair | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Oviewride protected void onDoSomethingOtherImportantThing(){ ... } } }  public class GameActivity extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); /* my code you dont need this assets=getAssets(); sGame= new GameView(this, GAME_WIDTH, GAME_HEIGHT); setContentView(sGame); getWindow().addFlags(WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); */ getWindow().getDecorView().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 // hide nav bair | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bair | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Oviewride protected void onDoSomethingOtherImportantThing(){ ... } } 

    A resposta já foi dada, mas aqui é como utilizair o modo Immersive.

    Na sua atividade:

    pouco antes do setContentview () …….

    chame o método: toggleHideyBair ();

    Acompanhe a documentation da documentation do Developer android e copie este método em sua atividade.

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