0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

@Previewで使えるプロパティ一覧

Last updated at Posted at 2025-05-06

@Preview で使えるプロパティ一覧(Jetpack Compose)

Jetpack Compose の UI を Android Studio のプレビューで確認するための @Preview アノテーションに指定できるパラメータ一覧です。

基本設定

プロパティ 説明 使用例
name プレビューの名前 @Preview(name = "My Preview")
group プレビューのグループ名 @Preview(group = "MyGroup")
showBackground 背景を表示するか @Preview(showBackground = true)
backgroundColor 背景色(ARGB) @Preview(backgroundColor = 0xFF00FF00)
widthDp 幅(dp) @Preview(widthDp = 320)
heightDp 高さ(dp) @Preview(heightDp = 480)

表示モード・UI関連

プロパティ 説明 使用例
showSystemUi ステータスバーやナビゲーションバーを表示 @Preview(showSystemUi = true)
showDecoration システムUIや背景などの装飾を表示 @Preview(showDecoration = true)
wallpaper 壁紙を表示 @Preview(wallpaper = "red")
fontScale フォントスケール(倍率) @Preview(fontScale = 1.5f)

デバイス・環境設定

プロパティ 説明 使用例
device 使用するデバイス @Preview(device = Devices.PIXEL_4)
hardware ハードウェア構成 @Preview(hardware = "pixel_4")
apiLevel Android API レベル @Preview(apiLevel = 30)
uiMode UIモード(ライト/ダーク) @Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
locale ロケール(言語・地域) @Preview(locale = "ja")

よく使う定数

device の例

  • Devices.DEFAULT
  • Devices.PHONE
  • Devices.TABLET
  • Devices.PIXEL_4
  • Devices.PIXEL_C
  • Devices.WEAR_OS_SMALL_ROUND
  • Devices.WEAR_OS_LARGE_ROUND

uiMode の例

  • Configuration.UI_MODE_NIGHT_NO(ライトモード)
  • Configuration.UI_MODE_NIGHT_YES(ダークモード)

使用例(複数設定)

@Preview(
    name = "Dark Mode - Pixel 4 - Japanese",
    showBackground = true,
    backgroundColor = 0xFF121212,
    uiMode = Configuration.UI_MODE_NIGHT_YES,
    device = Devices.PIXEL_4,
    locale = "ja",
    fontScale = 1.2f
)
@Composable
fun MyPreview() {
    MyComposable()
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?