2

How do I get rid of this tiny black space under the bottom "gesture bar"? Most apps extend all the way to the bottom, but I still see this tiny black bar on the bottom.

Main Activity XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.MainActivity">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragmentContainerView"
        android:name="com.myProject.fragments.SignUpFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout="@layout/sign_up_fragment" />
</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

yambo
  • 1,388
  • 1
  • 15
  • 34

2 Answers2

1

As I know you can't remove this bar but you can make that transparent

here a little hack of code

Method 1

this.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
    

as this will make your screen full and a transparent its a little hack but you can try this

here what above code does make your screen full screen and the gesture will be transparent an you will get your desire output

Method 2

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow(); // in Activity's onCreate() for instance
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

In your style change like this

<resources>
<style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

And in your activity where you want full screen to main layout give this flag

android:fitsSystemWindows="true"

Method 3

This code is not mine i have taken from the some website i forgot from where i have taken but give refrence soon

Here A funtion to make tranparent

fun Activity.transparentStatusAndNavigation(
    systemUiScrim: Int = Color.parseColor("#40000000") // 25% black
) {
    var systemUiVisibility = 0
    // Use a dark scrim by default since light status is API 23+
    var statusBarColor = systemUiScrim
    //  Use a dark scrim by default since light nav bar is API 27+
    var navigationBarColor = systemUiScrim
    val winParams = window.attributes


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        systemUiVisibility = systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
        statusBarColor = Color.TRANSPARENT
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        systemUiVisibility = systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
        navigationBarColor = Color.TRANSPARENT
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        systemUiVisibility = systemUiVisibility or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        window.decorView.systemUiVisibility = systemUiVisibility
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        winParams.flags = winParams.flags or
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        winParams.flags = winParams.flags and
                (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or
                        WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION).inv()
        window.statusBarColor = statusBarColor
        window.navigationBarColor = navigationBarColor
    }

    window.attributes = winParams
}

Hope this helps

0

How do I get rid of this tiny black space under the bottom "gesture bar"?

To extend the app to the most bottom, you need to make your app full screen with:

WindowCompat.setDecorFitsSystemWindows(window, false)

But this also draws the app over the top status bar; to avoid that you need to handle overlaps using insets by registering OnApplyWindowInsetsListener:

First give your root layout ConstraintLayout an id, say root:

val root = findViewById<ConstraintLayout>(R.id.root)
val onApplyWindowInsetsListener =
    OnApplyWindowInsetsListener { view: View, windowInsets: WindowInsetsCompat ->
        val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
        
        // Apply the insets as a margin to the root view in order to set the layout drawing area
        view.layoutParams = (view.layoutParams as FrameLayout.LayoutParams).apply {
            topMargin = insets.top // to draw below the top status bar
            leftMargin = insets.left
            rightMargin = insets.right
        }

        // Return CONSUMED if you don't want want the window insets to keep being
        // passed down to descendant views.
        WindowInsetsCompat.CONSUMED
    }
ViewCompat.setOnApplyWindowInsetsListener(root, onApplyWindowInsetsListener)

Now you need to hide the bottom navigation bar, and enable showing it whenever the user swipes up from the bottom:

WindowInsetsControllerCompat(window, window.decorView).apply {
    hide(WindowInsetsCompat.Type.navigationBars())
    systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}

This is working starting from API level 21.

Zain
  • 37,492
  • 7
  • 60
  • 84
  • This just froze my app and prevented it from running. I added all your code in the `onCreate` method of my activity. – yambo Feb 12 '22 at 17:12
  • @cabyambo Did you get any crash stacktrace that you would share? also which API level do you run this on? I've tested that before posting on different API levels, probably something else is raising that – Zain Feb 12 '22 at 17:15
  • Here are the two errors: `java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnApplyWindowInsetsListener(android.view.View$OnApplyWindowInsetsListener)' on a null object reference` and `Attempt to invoke virtual method 'void android.view.View.setOnApplyWindowInsetsListener(android.view.View$OnApplyWindowInsetsListener)' on a null object reference` – yambo Feb 12 '22 at 19:57
  • I think you didn't add `android:id="@+id/root"` to the `ConstraintLayout`; the main ViewGroup in the activity layout – Zain Feb 12 '22 at 20:13
  • I just ensured and tested again, it is there – yambo Feb 13 '22 at 00:34
  • @cabyambo I just tested that on a real device and working; the bottom gesture bar should be hidden by default; and you can show it by swiping from bottom to top; and it will automatically hide after a few secs – Zain Feb 13 '22 at 10:06