简体   繁体   English

如何删除Android的系统栏(页脚栏)

[英]How to remove system bar of android (footer bar)

I m working in an android project. 我在一个Android项目中工作。 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: 因此,我在AndroidManifest.xml中<manifest>标记下添加了以下几行:

<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 在相关的活动Java文件中,我在OnCreate方法下添加了以下行

sessionView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

But The system bar (footer bar) is not removed. 但是系统栏(页脚栏)未删除。

My Android version is 4.2.2 我的Android版本是4.2.2

Am I missing something? 我想念什么吗?

By default, you shouldn`t remove the statusbar, because it is a service from the Android UI. 默认情况下,您不应删除状态栏,因为它是Android用户界面中的一项服务。 Then Google let you hide it, however if the user swipes it up, it will come back. 然后,Google让您隐藏它,但是如果用户向上滑动它,它将返回。

But, yes it is possible to do if you have root access on the device. 但是,如果您在设备上具有root用户访问权限, 则可以这样做

This code can hide and show the StatusBar by killing it`s proccess and calling it back again. 此代码可以通过杀死进程并再次调用来隐藏和显示StatusBar。

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;

        }
    }


}

According to this link : 根据此链接

For android 4.4 + 对于Android 4.4 +

Try out immersive mode https://developer.android.com/training/system-ui/immersive.html 尝试沉浸式模式 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 应该在onCreate中添加代码,请参见setOnSystemUiVisibilityChangeListener

Here is also related question: Immersive mode navigation becomes sticky after volume press or minimise-restore 这也是一个相关的问题: 按下音量或最小化还原后,沉浸式导航变得发粘

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 https://stackoverflow.com/a/12605313/3847529

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM