2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Jetpack Compose] xmlでtextSizeがdp指定されている部分をComposeで書き直す [Android]

Posted at

内容

  • xmlでtextSizeがdp指定になっているところをCompose化する時にどうやって書くか。
  • Composeで、システムのフォントサイズに関係なく(依存せずに)、テキストサイズが一貫するように「.dp」を使用する方法

xmlの場合

<TextView
    ...
    android:textSize="16dp"
    tools:ignore="SpUsage" />

Compose化する場合

...
Text(
     ...
     fontSize = dpToSp(dp = 16.dp)
     )

@Composable
fun dpToSp(dp: Dp) = with(LocalDensity.current) { dp.toSp() }

見たサイト

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?