android / tv-samples

Multiple samples showing best practices in app development on Android TV.
Apache License 2.0
1.06k stars 338 forks source link

Set Focus on TextFiled on load? #153

Closed techker closed 8 months ago

techker commented 9 months ago

Not an issue, Just a question.

I have a login page that i would like to set the focus on the username box automaticly on page load?

i have tried to add val focusRequester = remember { FocusRequester() } val focusRequesterModifier = Modifier.focusRequester(focusRequester)

but can't add modifier to textField Or focusRequester not found?

...... modifier = Modifier .fillMaxWidth() .focusRequester(focusRequester) .....

TvTextField( value = username.value, label = "Username") { username.value = it } TvTextField() -> OutlinedTextField( textStyle = MaterialTheme.typography.bodyLarge, colors = TextFieldDefaults.outlinedTextFieldColors( focusedBorderColor = MaterialTheme.colorScheme.surface, cursorColor = MaterialTheme.colorScheme.surface, focusedLabelColor = MaterialTheme.colorScheme.surface, ), interactionSource = mutableInteractionSource, label = { Text(text = label) }, value = value, visualTransformation = visualTransformation, keyboardOptions = KeyboardOptions(keyboardType = keyboardType), onValueChange = onValueChange, )

vighnesh153 commented 9 months ago

Hey. Please ask questions on Stackoverflow and add the android-jetpack-compose-tv tag.