Alejandro Moya
03/15/2022, 1:30 PMfun dimensionResource(@DimenRes id: Int): Dp
returns DP dimensions, but there’s no SP version of it, is there a way to return the SP xml dimensions?Adam Powell
03/15/2022, 1:36 PMAlejandro Moya
03/15/2022, 1:36 PMmkrussel
03/15/2022, 1:39 PMAlejandro Moya
03/15/2022, 1:39 PMAdam Powell
03/15/2022, 1:42 PMdimensionResource
function reads android resources you should be able to write what you need hereAlejandro Moya
03/15/2022, 1:44 PMmkrussel
03/15/2022, 1:45 PMdimensionResource
does when loading an sp resources as dp. I was guessing it ignored the unit in the xml and just treated it as dp, but that is probably wrong.Alejandro Moya
03/15/2022, 1:46 PM@Composable
@ReadOnlyComposable
fun dimensionResource(@DimenRes id: Int): Dp {
val context = LocalContext.current
val density = LocalDensity.current
val pxValue = context.resources.getDimension(id)
return Dp(pxValue / density.density)
}
mkrussel
03/15/2022, 1:48 PMgetDimension
loads as pixel value, and then dimensionResource
converts to DP
.Alejandro Moya
03/15/2022, 1:52 PM