https://kotlinlang.org logo
#compose
Title
# compose
r

Rajashekar

02/10/2022, 5:30 PM
I'm trying to achieve this design with compose. I want to open dialpad with number input keyboard, this action triggers once I click FAB icon. I do not have TextField so cannot call the keyboard by default, in my case keyboard should open clicking on FAB. I have tried few things, but keyboard won't show up, any clue?
Copy code
Scaffold(
    floatingActionButton = {
        FloatingDialButton(
            keyboardController,
            focusRequester
        )
    },
    modifier = Modifier.focusRequester(focusRequester)
) {
    ScreenContent(uiState)
}
@Composable
fun FloatingDialButton(
    keyboardController: SoftwareKeyboardController?,
    focusRequester: FocusRequester,
) {
    FloatingActionButton(
        onClick = {
            focusRequester.requestFocus()
            keyboardController?.show()
        },
    ) {
        Icon(
            painterResource(id = R.drawable.ic_dialpad),
            contentDescription = "",
            tint = MaterialTheme.colors.onSecondary
        )
    }
}
d

Dmitrii Smirnov

02/11/2022, 9:38 AM
looks like this is TextField, so you have to set Modifier.focusRequester(forusRequester) to it
👍 1