Animating your keyboard using WindowInsets

Android Developers · 47K views · 2020 · 13:25

Open on YouTube

Software (other)UX & UI designtalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering how to hide system bars, detect or show the soft keyboard, and replace the deprecated systemUiVisibility flags with WindowInsets APIs.

Recommended by 7 people across 7 different months, 2015 to 2023.

What it is

Chris Banes of the Android Developers channel explains how Android 11 and Jetpack handle edge-to-edge layouts and WindowInsets. It covers checking keyboard visibility, hiding and showing the IME, immersive modes, and animating or dragging the keyboard in sync with app content.

What people said

Recommends Sourav Bagchi · 2020-08 · Stack Overflow · on “android.view.View.systemUiVisibility deprecated. What is the replacement?”

WindowCompat.setDecorFitsSystemWindows(window, false) Watch this tutorial [this video] from official Android Developers channel.

Recommends Konstantin Kuznetsov · 2020-10 · Stack Overflow · on “android.view.View.systemUiVisibility deprecated. What is the replacement?”

TL;DR snippet Wrapping in if-else structure needed to avoid java.lang.NoSuchMethodError: No virtual method setDecorFitsSystemWindows exception on older SDK versions. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { window.setDecorFitsSystemWindows(false) } else { window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN } Links with full information about insets and fullscreen modes in Android 11 [LINK] [this video]

Recommends James · 2020-11 · Stack Overflow · on “android.view.View.systemUiVisibility deprecated. What is the replacement?”

For compatibility, use WindowCompat and WindowInsetsControllerCompat . You'll need to upgrade your gradle dependency for androidx.core to at least 1.6.0-alpha03 so that there will be support for setSystemBarsBehavior on SDK < 30. private fun hideSystemUI() { WindowCompat.setDecorFitsSystemWindows(window, false) WindowInsetsControllerCompat(window, mainContainer).let { controller -> controller.hide(WindowInsetsCompat.Type.systemBars()) controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE } } private fun showSystemUI() { WindowCompat.setDecorFitsSystemWindows(window, true) WindowInsetsControllerCompat(window, mainContainer).show(WindowInsetsCompat.

Recommends James · 2020-11 · Stack Overflow · on “Immersive fullscreen on Android 11”

For compatibility, use WindowCompat and WindowInsetsControllerCompat . You'll need to upgrade your gradle dependency for androidx.core to at least 1.6.0-alpha03 so that there will be support for setSystemBarsBehavior on SDK < 30. mainContainer is the top-level ConstraintLayout in my activity. private fun hideSystemUI() { WindowCompat.setDecorFitsSystemWindows(window, false) WindowInsetsControllerCompat(window, mainContainer).let { controller -> controller.hide(WindowInsetsCompat.Type.systemBars()) controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE } } private fun showSystemUI() { WindowCompat.setDecorFitsSystemWindows(window, true) WindowInsets

Recommends Sergey Chilingaryan · 2021-05 · Stack Overflow · on “How can I close/hide the Android soft keyboard programmatically?”

Thank God it’s officially supported after 11 years [this video] . First add dependency implementation 'androidx.core:core-ktx:1.7.0' to app gradle. Then get InsetsController from ViewCompat or WindowCompat class. Finally use hide() and show() function of InsetsController Add support for Dialog. Available in BottomSheetDialog. @Rondev. Using a safer way to get activity instead of directly cast from context. import android.app.Activity import android.app.Dialog import android.content.Context import android.content.ContextWrapper import android.view.View import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.fragment.a

Recommends Vidyesh Churi · 2021-06 · Stack Overflow · on “android.view.View.systemUiVisibility deprecated. What is the replacement?”

According to Chris Banes @ Android Developers official youtube channel [this video] use following code class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private lateinit var view: View override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) view = binding.root setContentView(view) } override fun onWindowFocusChanged(hasFocus: Boolean) { super.onWindowFocusChanged(hasFocus) if (hasFocus) hideSystemUI() } private fun hideSystemUI() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // Tell the window that we want to handle/fit any system windows WindowCompat.setDecor

Recommends Vidyesh Churi · 2021-06 · Stack Overflow · on “Immersive fullscreen on Android 11”

According to Chris Banes @ Android Developers official youtube channel [this video] use following code class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private lateinit var view: View override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) view = binding.root setContentView(view) } override fun onWindowFocusChanged(hasFocus: Boolean) { super.onWindowFocusChanged(hasFocus) if (hasFocus) hideSystemUI() } private fun hideSystemUI() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // Tell the window that we want to handle/fit any system windows WindowCompat.setDecor

Recommends thaovd1712 · 2022-07 · Stack Overflow · on “Android: how can i tell if the soft keyboard is showing or not?”

I finally find solution after looking for several class. I decide to use WindowsInset because it not call every seconde like use global layout. There is a video talking about how to use windowsInset. Link [this video]

Recommends André Spadetto Leão · 2022-09 · Stack Overflow · on “Center Android WindowBackground with Activity ImageView”

None of the solutions above solved this problem for me. I have a single activity app and after a while, of researching a solution I got solved by adding the code below to my splash screen fragment onViewCreated : WindowCompat.setDecorFitsSystemWindows(requireActivity().window, false) This code says to android that we will handle the window insets ourselves. So it doesn't adapt the layout with the status bar and the bottom navigation bar. I also added: override fun onDestroy() { WindowCompat.setDecorFitsSystemWindows(requireActivity().window, true) super.onDestroy() } Just to keep the behavior that I currently had on the rest of the app. A great resource that helped me with the solution was:

Cites hata · 2015-10 · Stack Overflow · on “Overlapping shadow effect remains on Navigation Drawer's NavigationView”

At last, I made it. The solution is using FLAG_LAYOUT_NO_LIMITS together with FLAG_FULLSCREEN to the android.view.Window [LINK] object. getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); This has gotten rid of both of the shadows perfectly. [LINK] lcw_gg's comment was very useful clue to manipulating android.view.Window [LINK] . Special thanks to him. Update for Android 11 Unfortunately, the problem returns when I update my phone to Android 11 (API-30). The above solution isn't effective any more. An alternate solution is @AllanVeloso's answer [LINK] using app:insetForeground="@null" And I also got a new solution. Just getting