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).
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).ボタンにツールチップを付けることができますが,ボタングループをページの幅いっぱいに広げ,ボタンを等幅にするのが面倒です.
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).ボタンの間のすき間が狭いからでしょうか?
https://m3.material.io/blog/building-with-m3-expressiveの例が変です:square connected button groupの例で,選択されたボタンと隣接するボタンの幅が一時的に変化しています.