简体   繁体   English

如何去除出现在底部的黑条?

[英]How to remove the black bar appearing at the bottom?

I am new to Android Development.我是 Android 开发的新手。 I want my app to support the screen size of my device ie 1080 x 2160 pixels .我希望我的应用程序支持我设备的屏幕尺寸,即1080 x 2160 pixels Currently there is a black bottom bar that is displayed in place of where the navigation buttons would have been.目前有一个黑色的底部栏显示在导航按钮的位置。

在此处输入图片说明

Please note that I do not wantFull Screen Mode .请注意,我不想要Full Screen Mode I have disabled the button navigation on my device.我已禁用设备上的按钮导航。 It is only for this app that that the bottom black rectangle is showing.仅针对此应用程序显示底部黑色矩形。 I just want my app to support the gesture navigation system of my device instead of buttons.How do I make the bottom bar go away using Java ( Android Studio ) so that my app utilizes that space?我只希望我的应用程序支持我的设备的手势导航系统而不是按钮。如何使用 Java ( Android Studio ) 使底部栏消失,以便我的应用程序利用该空间?

question is old but I faced the same issue and didnot find the solution on SO.问题很老,但我遇到了同样的问题,并没有在 SO 上找到解决方案。
this problem occurs for long screens长屏出现这个问题

We recommend that you design your app to support aspect ratios of 2.1 or higher.我们建议您将应用设计为支持 2.1 或更高的纵横比。 For this, you would add the following to the "application" element in your Manifest file:为此,您需要将以下内容添加到 Manifest 文件中的“application”元素中:

<meta-data android:name="android.max_aspect" android:value="2.1" />

from here 从这里

I had the same issue, updated manifest file with this or remove if you have one.我遇到了同样的问题,用这个更新了清单文件,如果你有的话,请删除。

before

<meta-data
    android:name="android.max_aspect"
    android:value="2.1" />

after

<meta-data
    android:name="android.max_aspect"
    android:value="2.4" />

working for me now.现在为我工作。

嗨,请尝试以下代码

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

You can try this你可以试试这个

@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);
    }
}

Try to add this code尝试添加此代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    hideSystemUI(this, 1000);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        // Hide bar after 1 second
        hideSystemUI(this, 1000);
    }
}

public static void hideSystemUI(@NonNull final Activity activity, final int delayMs) {
    View decorView = activity.getWindow().getDecorView();
    int uiState = View.SYSTEM_UI_FLAG_IMMERSIVE
            | 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;
    final Handler handler = new Handler();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            if (visibility == View.VISIBLE) {
                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        hideSystemUI(activity, 1000);
                    }
                };
                handler.postDelayed(runnable, delayMs);
            }
        }
    });
    decorView.setSystemUiVisibility(uiState);
}

WARNING警告

If you have two activities, add this before changing如果您有两个活动,请在更改之前添加此项

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(null);

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

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