Robert
Robert

Reputation: 323

Jetpack Compose: Keyboard covers the TextField in dialog

In short: using Jetpack Compose, the keyboard overlaps the TextField when it is opened in an AlertDialog. I've tried everything I've found:

I've created a GitHub repository with a demo project: Demo project - TextField covered by keyboard

Can you help me to understand what am I missing? I'm completely out of ideas.

Screenshots:
Dialog with TextField TextField covered by the keyboard

UPDATE - SOLVED

Based on the answer of @Shubham Thorat, I used adjustPan in the following way:

Upvotes: 6

Views: 4425

Answers (4)

Ransford Owusu
Ransford Owusu

Reputation: 114

I have an answer, which will always work for modal bottom sheet with a textfiled. Here is a basic implementation.

  1. Declare a bottom sheet state, and set the skipPartiallyExpanded argument to true.
  2. Supply the state to the sheetState of the ModalBottomSheet.
  3. Declare a fixed height to the ModalSheet

Code Example

val sheetState = rememberModalBottomSheetState(true)
val inputValue =  remember{ mutableStateOf("") }

ModalBottom(
    onDismissRequest={},
    sheetState = sheetState,
    modifier = Modifier.fillMaxWidth(),
    height = 300.dp, //assuming the height is 300 dp
    content = {
        Column(modifier = Modifier.padding(10.dp){
            TextField(
            modifier = Modifier.fillMaxWidth(),
            value = inputValue,
            onValueChanged= { inputValue.value = it },
           )
        }
     }
  )

Upvotes: 0

Asad khan
Asad khan

Reputation: 7

android:windowSoftInputMode="adjustResize"

Column(
    modifier = Modifier
        .fillMaxHeight()
        .imePadding()
    
)

Upvotes: 0

Shubham Thorat
Shubham Thorat

Reputation: 76

Can you try this one:

android:windowSoftInputMode="adjustPan"

Upvotes: 6

F.Mysir
F.Mysir

Reputation: 4176

Try this on your column:

Column(
    modifier = Modifier
        .fillMaxHeight()
        //add this
        .imePadding()
        .verticalScroll(scrollState),
) {
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(boxHeight)
            .background(LightYellow)
    ) {

    }

    CustomTextField(textFieldValueState = textFieldValueState)
}

Upvotes: 3

Related Questions