'How to remove the space under the bottom pill gesture bar Android?
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>
Solution 1:[1]
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.
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zain |
| Solution 2 |

