0

I'm tryin to hide soft key on a bottom clicked in bottom sheet dialog fragment. I already tried this :

    try {
        val view: View? = requireActivity().currentFocus
        if (view != null) {
            (requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(
                view.windowToken,
                0)
        }
    } catch (e: Exception) {
        Logger.e(TAG, "can't hide the softKey --> ${e.message}", e)
    }

buy its not working on bottom sheet dialog

Omid Kzm
  • 78
  • 5

2 Answers2

0

Try the following:

    getDialog().getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Amirhosein
  • 4,266
  • 4
  • 22
  • 35
0

Are you sure requireActivity().currentFocus isn't returning null? That seems to always happen when I try your code, and if it does it makes sense that it doesn't do anything. I'd suggest getting a view another way. As long as you're calling the function after you have returned from onCreateView you can just use view (from getView()):

val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view?.windowToken, 0)
Håkon Schia
  • 931
  • 1
  • 7
  • 12