How to Hide System Navigation Bar in Tablets

How to hide the system navigation bar in android

NOTE : System Navigation will still appear when ever you show any AlertDialog but when you dismiss it , It will hide again. If you still not want this behavior then use Center View to create Alert like view.

You can try following approach which i have used .

/**
* Hide system NavigationBar and StatusBar
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public void hideNavigationBar()
{
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
Log.i("LOG","Menu Shown is this"+ visibility);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE);

}
});
}

Call above method from onResume of Activity and make sure you override following method in activity.

@Override
@TargetApi(Build.VERSION_CODES.KITKAT)
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_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE
);
}
}

You should use following approach to hide navigation when Alert created.

public static void showAlert(Context context,String title,String message) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(title);
alertDialogBuilder.setMessage(message);
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
final AlertDialog alertDialog = alertDialogBuilder.create();
//Here's the magic..
//Set the dialog to not focusable (makes navigation ignore us adding the window)
alertDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

alertDialog.show();
//Set the dialog to immersive
alertDialog.getWindow().getDecorView().setSystemUiVisibility(
((Activity)context).getWindow().getDecorView().getSystemUiVisibility());

//Clear the not focusable flag from the window
alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}

I found above working code from this SO

How to Hide System Navigation Bar in Tablets?

In Tablets running Android 4+, it is not possible to hide the System / Navigation Bar.

From documentation (Controls for system UI visibility section) :

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
).

However, you could try to dim the system bar as done sometimes during gaming and video playback.

The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN
flag. When set, this flag enables “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.

Android tablet navigation bar won't hide

You cannot permanently hide the system bar on a tablet.

SYSTEM_UI_FLAG_HIDE_NAVIGATION on Android 4.1 and higher will hide the system bar, but it will reappear as soon as the user does anything.

How to hide navigation bar permanently in android activity?

Snippets:

FullScreenFragment.java

HideNavigationBarComponent.java


This is for Android 4.4+

Try out immersive mode https://developer.android.com/training/system-ui/immersive.html

Fast snippet (for an Activity class):

private int currentApiVersion;

@Override
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

currentApiVersion = android.os.Build.VERSION.SDK_INT;

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;

// This work only for android 4.4+
if(currentApiVersion >= Build.VERSION_CODES.KITKAT)
{

getWindow().getDecorView().setSystemUiVisibility(flags);

// Code below is to handle presses of Volume up or Volume down.
// Without this, after pressing volume buttons, the navigation bar will
// show up and won't hide
final View decorView = getWindow().getDecorView();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
{

@Override
public void onSystemUiVisibilityChange(int visibility)
{
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{
decorView.setSystemUiVisibility(flags);
}
}
});
}

}

@SuppressLint("NewApi")
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
if(currentApiVersion >= Build.VERSION_CODES.KITKAT && 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);
}
}

If you have problems when you press Volume up or Volume down that your navigation bar show. I added code in onCreate see setOnSystemUiVisibilityChangeListener

Here is another related question:

Immersive mode navigation becomes sticky after volume press or minimise-restore

Hide Tablet system bar

Finally after searching lots of time I got some alternativ for my requirement.

I know this is not a good idea for a programmer to back off from this situation but for my time limit I used this way...

I found this link and application which fullfil my requirement

http://www.42gears.com/blog/2012/04/how-to-hide-bottom-bar-in-rooted-android-3-0-tablets-using-surelock/

please visit this once if you want this type of requirement in your application ....

Thanks to all for helping me in my problem...



Related Topics



Leave a reply



Submit