android / tv-samples

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

Set Focus on TextFiled on load? #153

Closed techker closed 3 months ago

techker commented 4 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 4 months ago

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