Tobias Preuss
01/23/2023, 2:14 PMandroidx.compose.material3.OutlinedTextField
?
In the following example the cursor is not visible.
@ExperimentalMaterial3Api
@Composable
fun outlinedTextColors() = outlinedTextFieldColors(
textColor = baseTextColor(),
cursorColor = colorResource(android.R.color.holo_green_dark), // <---
unfocusedBorderColor = baseTextColor(),
unfocusedLabelColor = baseTextColor(),
focusedLabelColor = baseTextColor(),
placeholderColor = colorResource(R.color.tertiaryTextColor),
focusedTrailingIconColor = baseIconColor(),
)
@ExperimentalMaterial3Api
@Composable
private fun MyOutlinedTextField(
configuration: Configuration,
onTextChanged: (String) -> Unit,
modifier: Modifier = Modifier,
) {
OutlinedTextField(
modifier = modifier,
label = { Text(configuration.label, subheadlineMedium) },
value = limitedText,
onValueChange = { onTextChanged(it) },
textStyle = subheadlineMedium,
colors = outlinedTextColors(), // <---
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done)
)
}
Related:
• https://github.com/material-components/material-components-android/issues/3067
• https://issuetracker.google.com/issues/240256666Ale Stamato
01/25/2023, 9:55 AMTobias Preuss
01/25/2023, 4:20 PMAle Stamato
01/25/2023, 7:35 PMcolors = TextFieldDefaults.outlinedTextFieldColors(
cursorColor = Color(Pink)
),
do u have a min repro (a small project)? I cant reproduce, locally cursorColor works fine for me (using the same system green)Tobias Preuss
01/25/2023, 8:12 PMcursorColor
explicitly.@ExperimentalMaterial3Api
@Composable
private fun MyOutlinedTextField(
configuration: Configuration,
onTextChanged: (String) -> Unit,
modifier: Modifier = Modifier,
) {
androidx.compose.material3.OutlinedTextField(
modifier = modifier,
value = limitedText,
onValueChange = { onTextChanged(it) },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done)
)
}
... the cursor still does not show up on the device.
It does show up in the Android Studio Preview, though: purple color.
Hardcoding the color works in the Preview, too. But not on the device.OutlinedTextField
pick up some theme automatically which colors the cursor? How would I know?Ale Stamato
01/30/2023, 4:08 PMTobias Preuss
01/30/2023, 4:08 PMAle Stamato
01/30/2023, 4:12 PMoutlinedTextFieldColors
defaults ->
cursorColor: Color = OutlinedTextFieldTokens.CaretColor.toColor()
and then OutlinedTextFieldTokens
defines CaretColor = ColorSchemeKeyTokens.Primary
if you do not override it, the cursor colour should be the primary defined in your material themeTobias Preuss
01/30/2023, 4:22 PMcolorPrimary
?
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">#000</item>
...
</style>
Ale Stamato
01/30/2023, 5:50 PMMaterialTheme(
colorScheme = colorScheme,
typography = AppTypography,
content = content
)
then colorScheme has a primary.Tobias Preuss
01/30/2023, 6:05 PMAle Stamato
01/30/2023, 6:38 PMTobias Preuss
01/30/2023, 8:26 PMOutlinedTextField
into MaterialTheme
which I do not until now.textStyle
in combination with a composition local if I understand you correctly.Ale Stamato
01/31/2023, 12:39 AMTobias Preuss
02/02/2023, 11:23 AM