Luis Mierez
06/21/2021, 2:54 PMMaterialTheme colors and typography. If I create a MaterialTheme with a primary color of Color.Blue, and a button TextStyle that has the color set to Color.White , which color takes precedent when using a TextButton ?Luis Mierez
06/21/2021, 3:11 PMSe7eN
06/21/2021, 4:03 PMMaterialTheme color takes precedence.Se7eN
06/21/2021, 4:03 PMLuis Mierez
06/21/2021, 4:39 PMTextButton … TextButton uses the primaryColor for the text color, but it is pulling the default from the button TextStyleChris Sinco [G]
06/21/2021, 4:56 PMChris Sinco [G]
06/21/2021, 4:57 PMcolors parameter. This is the colors defined by default if you don’t do soLuis Mierez
06/21/2021, 4:58 PMTextButton(
onClick = updateInfoOnClick,
modifier = Modifier.weight(1f, true)
) {
Text(text = stringResource(id = R.string.update_my_info))
}Luis Mierez
06/21/2021, 4:58 PMChris Sinco [G]
06/21/2021, 4:59 PMMaterialTheme.colors.primary for contentColorLuis Mierez
06/21/2021, 5:01 PMMaterialTheme.color.primary which is the default param for the TextButton , but it’s pulling in the default for the button TextStyleChris Sinco [G]
06/21/2021, 5:01 PMTextStyle that has Color.White and how are you using it in the TextButton?Luis Mierez
06/21/2021, 5:01 PMMaterialTheme I’m passing in the colors with a primary color of our blueChris Sinco [G]
06/21/2021, 5:02 PMTextButton within that MaterialTheme hierarchy?Luis Mierez
06/21/2021, 5:02 PMTypography(
h1 = TextStyle(
fontFamily = Roboto,
fontWeight = FontWeight.Light,
fontSize = 96.sp,
color = Color.Black
),
h4 = TextStyle(
fontFamily = Roboto,
fontWeight = FontWeight.Medium,
fontSize = 34.sp,
color = Color.Black
),
body1 = TextStyle(
fontFamily = Roboto,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
color = Color.Black
),
button = TextStyle(
fontFamily = Roboto,
fontWeight = FontWeight.Medium,
letterSpacing = 0.sp
)
)Luis Mierez
06/21/2021, 5:02 PMLuis Mierez
06/21/2021, 5:03 PMChris Sinco [G]
06/21/2021, 5:06 PMbutton style in Typography because if you look at the Button implementation, it’s using a CompositionLocal within the Surface which is after using colors pulled from the Button parametersChris Sinco [G]
06/21/2021, 5:07 PMTextStyles within Typography and instead use colors in the MaterialTheme or set colors at the component level. @Louis Pullen-Freilich [G] might have more insight as wellLuis Mierez
06/21/2021, 5:07 PMLuis Mierez
06/21/2021, 5:07 PMTypography object it’ll still won’t pull in the primary colorChris Sinco [G]
06/21/2021, 5:08 PMit’ll still won’t pull in the primary colorThat seems like a bug
Louis Pullen-Freilich [G]
06/21/2021, 5:10 PMTextStyle are always used first, but in a Material app you should not set colors on a style - colors are separate from text.
Text (and icons) by default use LocalContentColor, which is provided by different components, such as AppBar and Button. This ensures that text will follow the correct theme color for the background it is on, and also so it will automatically adjust to light / dark themes.
I would recommend removing all the color = Color.Black from your Typography stylesLuis Mierez
06/21/2021, 5:16 PMLuis Mierez
06/21/2021, 6:01 PMmdcTheme and I was passing setTextColors to true which sets the colors to the Typography object, and it was overriding my theme color. I appreciate all the help!