0

I m working in an android project. This project contains many activities. I m trying to remove the system bar (footer bar) from one fo the existing activities

So I added the following lines in the AndroidManifest.xml under the <manifest> tag:

<category android:name="android.intent.category.HOME" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

and in the related activity java file I added the following line under the OnCreate method

sessionView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

But The system bar (footer bar) is not removed.

My Android version is 4.2.2

Am I missing something?

MOHAMED
  • 41,599
  • 58
  • 163
  • 268
  • Have you looked into WindowManager.LayoutParams? Not sure what you need is there but not a bad place to start. – zgc7009 Dec 10 '14 at 17:38

3 Answers3

1

By default, you shouldn`t remove the statusbar, because it is a service from the Android UI. Then Google let you hide it, however if the user swipes it up, it will come back.

But, yes it is possible to do if you have root access on the device.

This code can hide and show the StatusBar by killing it`s proccess and calling it back again.

package com.example.statusbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class MainActivity extends Activity {

    String commandToExecute;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);

        commandToExecute = "/system/xbin/su";
        executeShellCommand(commandToExecute);

        Button btHideStatusBar = (Button) findViewById(R.id.buttonHide);
        Button btShowStatusBar = (Button) findViewById(R.id.buttonShow);


        btHideStatusBar.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                commandToExecute = "/system/xbin/su -c /system/bin/service call activity 42 s16 com.android.systemui";
                executeShellCommand(commandToExecute);

            }
        });

    btShowStatusBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            commandToExecute = "/system/xbin/su -c /system/bin/am startservice -n com.android.systemui/.SystemUIService";
            executeShellCommand(commandToExecute);

        }
    });

    }

    private boolean executeShellCommand(String command) {
        try {

            Runtime.getRuntime().exec(command);

            return true;
        } catch (Exception e) {
            return false;

        }
    }


}
Machado
  • 14,105
  • 13
  • 56
  • 97
1

According to this link:

For android 4.4 +

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

Fast snippet:

@SuppressLint("NewApi")
    protected void onCreate(Bundle 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 >= 19) {

        getWindow().getDecorView().setSystemUiVisibility(flags);
        // Code below is for case when you press Volume up or Volume down.
        // Without this after pressing valume buttons navigation bar will
        // show up and don'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 >= 19 && 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 there is problems when pressing Volume up or Volume down that your navigation bar show. Should added code in onCreate see setOnSystemUiVisibilityChangeListener

Here is also related question: Immersive mode navigation becomes sticky after volume press or minimise-restore

Community
  • 1
  • 1
MOHAMED
  • 41,599
  • 58
  • 163
  • 268
0

You cannot hide the system bar. You can dim the bar color. Below link may help you to know why you cant hide it and how to dim the bar.

https://stackoverflow.com/a/12605313/3847529

Community
  • 1
  • 1
Aravindan K
  • 101
  • 3
  • 18