-1

I have a project in which i want to make the Layouts FullScreen or make the Android Soft keys hidden. I tried solutions by Googling like

  1. Hide Action Bar
  2. SYSTEM_UI_FLAG_HIDE_NAVIGATION
  3. Also test the change of theme in app Theme.AppCompat.Light.NoActionBar

I disabled Back Key using this code :

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) 
{    
        if(keyCode == KeyEvent.KEYCODE_HOME)
        {
            Log.i("Home Button", "Clicked");
        }
        if(keyCode==KeyEvent.KEYCODE_BACK)
        {

            finish();
        }
        return false;
};

But i want to disable all Soft Keys or Hide them. Note that the device in which my app will work is Lenovo Tab2 and has Virtual Soft keys like this Pic.

Community
  • 1
  • 1
Alireza
  • 89
  • 2
  • 15

4 Answers4

5

Use this code in onCreate method and after setContentView(). It helped me.

if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT )
        {
            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 bar
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY );
        }
oalpayli
  • 227
  • 1
  • 2
  • 9
  • Really Thx for that reply. such a great Idea. But i there any other way to disable them? I mean it hides and if i scroll down. As you saw i disabled Back in onKeyDown method. Can i disable others in this way? – Alireza Dec 28 '15 at 11:11
1

Try this:

View.setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LOW_PROFILE
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Milos Lulic
  • 627
  • 5
  • 22
1

If you just need to hide the menu items just setVisible to false.Inside onCreateOptionsMenu say menu.findItem(R.id.action_back).setVisible(false); I have tried something similar in my app.This is the code I used inside my onCreateOptionsMenu.

 if (menu != null) {
        menu.findItem(R.id.action_register).setVisible(false);
        menu.findItem(R.id.action_search).setVisible(false);
        menu.findItem(R.id.action_settings).setVisible(false);
        menu.findItem(R.id.action_refresh).setVisible(false);
    }
  • Thank you this solved my problem.So you don't actually need another toolbar you just need to show/hide the menu items.Awesome answer dude! Thank you so much –  Dec 28 '15 at 10:33
0

You may observe that the immersive mode is lost when the activity loses focus. It may not come back to immersive mode after regaining focus. To make sure the app doesn't lose the immersive mode on focus changes, implement the code in onWindowFocusChangedmethod, NOT on onCreate method.

Source: https://developer.android.com/training/system-ui/immersive.html

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
    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_STICKY);}
}