【Jetpack Compose】Compose Settings で数分で設定画面を作る

意外と面倒な設定画面が数分でできます。

This library provides a set of Settings like composable items to help android Jetpack Compose developers build complex settings screens without all the boilerplate

このライブラリは、開発者がボイラープレートなしで複雑な設定画面を構成できるアイテム詰め合わせです。

👉 alorma/Compose-Settings: Android #JetpackCompose Settings library hatena-bookmark

以下コピペですぐに表示できます。


implementation 'com.github.alorma:compose-settings-ui:$version'


SettingsMenuLink(
  icon = { Icon(imageVector = Icons.Default.Wifi, contentDescription = "Wifi") },
  title = { Text(text = "Link") },
  subtitle = { Text(text = "This is a longer text") },
  onClick = {},
)
Divider()
SettingsSwitch(
  icon = { Icon(imageVector = Icons.Default.Wifi, contentDescription = "Wifi") },
  title = { Text(text = "Switch") },
  subtitle = { Text(text = "This is a longer text") },
  onCheckedChange = { },
)
Divider()
SettingsCheckbox(
  icon = { Icon(imageVector = Icons.Default.Wifi, contentDescription = "Wifi") },
  title = { Text(text = "Checkbox") },
  subtitle = { Text(text = "This is a longer text") },
  onCheckedChange = { },
)
Divider()
SettingsSlider(
  icon = {
    Icon(
      imageVector = Icons.Default.BrightnessMedium,
      contentDescription = "Brightness Medium"
    )
  },
  title = { Text(text = "Slider") },
)
Divider()
SettingsList(
  title = { Text(text = "List") },
  subtitle = { Text(text = "Select a fruit") },
  items = listOf("Banana", "Kiwi", "Pineapple"),
  action = {
    IconButton(onClick = {  }) {
      Icon(
        imageVector = Icons.Default.Clear,
        contentDescription = "Clear",
      )
    }
  },
)

alorma/Compose-Settings: Android #JetpackCompose Settings library


UIだけでなく Preferences への読み書きも用意されています。


implementation 'com.github.alorma:compose-settings-storage-preferences:$version'

state を更新するとそのまま Preferences に書き込みされます。


val preferenceStorage = rememberPreferenceBooleanSettingState(
    key = "switch",
    defaultValue = false,
)
SettingsCheckbox(
    state = preferenceStorage, // *
    icon = {

超便利です!!

コードも良い参考にもなります。

👉 【Jetpack Compose】Icon() や Image() で ImageVector をより便利に使う hatena-bookmark


関連ワード:  AndroidAndroidStudioJetpackComposeKotlinおすすめライブラリ便利な設定開発