Show entire bottom sheet with EditText above Keyboard

后端 未结 8 1317
北恋
北恋 2020-11-30 21:27

I\'m implementing a UI where a bottom sheet will appear above the keyboard with an EditText for the user to enter a value. The problem is the View is being partially overlap

8条回答
  •  有刺的猬
    2020-11-30 22:10

    This might be a redundant answer. Although just pointing out the issue. If you're using BottomSheetDialogFragment, the only way is to enable the attribute android:windowIsFloating to true. This will enable the whole window to be on top of whatever is trying to take the space behind it.

    
    

    Then in your onCreate() of your dialog, set this style.

    override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            // set the window no floating style
            setStyle(DialogFragment.STYLE_NORMAL, R.style.AppRoundedBottomSheetDialogThemeNoFloating)
    }
    

    This is handy for those who frequently use bottom sheets and may want to deal with EditText and soft keyboard overlapping each other.

    Note: The class KeyboardUtil by mikepenz has an issue in which on certain phones, the content view with input field is automatically pushed above keyboard despite giving bottom padding to the whole content view supplied.

提交回复
热议问题