Button Group
ボタングループが分かりにくいです.
1⃣選択されたボタンの角が四角く,選択されていないボタンの角が丸いボタングループ,2⃣選択されたボタンの角が丸く,ボタングループの端の角が丸く,それ以外の角が四角いボタングループ(round connected button group)だけでなく,3⃣(たぶん)選択されたボタンの角が丸く,選択されていないボタンの角が四角いボタングループ(square connected button group)もあるようです(https://m3.material.io/components/button-groups/specs).
standard button group:
選択されたボタンと隣接するボタンの幅が一時的に変化します(https://m3.material.io/components/button-groups/specs,https://m3.material.io/components/button-groups/guidelines).その際,隣接するボタンのコンテンツが中心からずれています(https://issuetracker.google.com/issues/552043096).
OverflowIndicatorにより,画面の横幅を超えるボタンをメニューに入れることができます(https://m3.material.io/components/button-groups/guidelines).メニュー内のボタンが選択されているのが分からないです(https://issuetracker.google.com/issues/585624838).toggleableItemではなくcustomItemを使用することで,メニュー内のボタン(本当はメニューアイテム)に手動でアイコンを付けることができます(ToggleButtonだけではなくElevatedToggleButton,FilledTonalToggleButton,OutlinedToggleButtonを使用することもできます.ボタンにツールチップを付けることもできますが,選択されたボタンと隣接するボタンの幅が一時的に変化しなくなります).
1⃣選択されたボタンの角が四角く,選択されていないボタンの角が丸いボタングループです.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
val themes = listOf(
"0",
"1",
"2"
)
var selectedIndex by rememberSaveable {
mutableIntStateOf(
0
)
}
ButtonGroup(
{
ButtonGroupDefaults.OverflowIndicator(
it
)
}
) {
themes.forEachIndexed { index, theme ->
toggleableItem(
selectedIndex == index,
theme,
{
selectedIndex = index
}
)
}
}
connected button group:
ボタングループをページの幅いっぱいに広げます(https://m3.material.io/components/button-groups/guidelines).ボタンにツールチップを付けることはできますが,ボタングループをページの幅いっぱいに広げ,ボタンを等幅にするのは面倒です.Googleドライブのボタングループはページの幅いっぱいではなく,ボタングループ内のボタンはToggleButtonではなくFilledTonalToggleButtonです.
RowではなくFlowRowを使用することにより,画面の横幅を超えるボタンを次の行に配置することができます(https://developer.android.com/develop/ui/compose/layouts/flow?hl=ja,https://github.com/material-components/material-components-android/blob/master/docs/components/ButtonGroup.md#overflow-mode—wrap).
shapesを設定しないと1⃣選択されたボタンの角が四角く,選択されていないボタンの角が丸いボタングループになります(想定外の使い方でしょうか?).shapesを設定すると2⃣選択されたボタンの角が丸く,ボタングループの端の角が丸く,それ以外の角が四角いボタングループ(round connected button group),3⃣選択されたボタンの角が丸く,選択されていないボタンの角が四角いボタングループ(square connected button group)になります.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Row(
Modifier.fillMaxWidth(),
Arrangement.spacedBy(
ButtonGroupDefaults.ConnectedSpaceBetween
)
) {
val themes = listOf(
"0",
"1",
"2"
)
var selectedIndex by rememberSaveable {
mutableIntStateOf(
0
)
}
themes.forEachIndexed { index, theme ->
ToggleButton(
selectedIndex == index,
{
selectedIndex = index
},
Modifier.weight(
1f
),
shapes = when (index) {
0 -> ButtonGroupDefaults.connectedLeadingButtonShapes()
themes.lastIndex -> ButtonGroupDefaults.connectedTrailingButtonShapes()
else -> ButtonGroupDefaults.connectedMiddleButtonShapes()
}//2⃣
// shapes = ButtonGroupDefaults.connectedMiddleButtonShapes()//3⃣
) {
Text(
theme
)
}
}
}
テーマの選択にはconnected button groupがすすめられているようですが,standard button groupと比べ,選択されていないボタンが分かりにくいです(https://m3.material.io/components/button-groups/guidelines).ボタンの間のすき間が狭いからでしょうか? ToggleButtonではなくElevatedToggleButton,FilledTonalToggleButton,OutlinedToggleButtonを使用することにより,選択されていないボタンが分かりやすくなります(ElevatedToggleButtonはいまいちです).
https://m3.material.io/blog/building-with-m3-expressiveの例が変です:square connected button groupの例で,選択されたボタンと隣接するボタンの幅が一時的に変化しています.