简体   繁体   中英

How to remove the black bar appearing at the bottom?

I am new to Android Development. I want my app to support the screen size of my device ie 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 . 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?

question is old but I faced the same issue and didnot find the solution on SO.
this problem occurs for long screens

We recommend that you design your app to support aspect ratios of 2.1 or higher. For this, you would add the following to the "application" element in your Manifest file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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