@@ -28,9 +28,18 @@ class MainActivity : ComponentActivity() {
2828 modifier = Modifier .fillMaxSize(),
2929 color = MaterialTheme .colors.background
3030 ) {
31- Sample1 ()
32- // Sample2()
33- // Sample3()
31+ Scaffold (
32+ topBar = {
33+ TopAppBar (
34+ title = { Text (" Title" ) },
35+ actions = {
36+ Sample1 ()
37+ // Sample2()
38+ // Sample3()
39+ }
40+ )
41+ }
42+ ) {}
3443 }
3544 }
3645 }
@@ -43,105 +52,78 @@ fun Context.toast(message: CharSequence) =
4352@Composable
4453fun Sample1 () {
4554 val context = LocalContext .current
46- Scaffold (
47- topBar = {
48- TopAppBar (
49- title = { Text (" Sample 1" ) },
50- actions = {
51- OverflowMenu {
52- shownIconsCount = 2
53- icons {
54- icon {
55- imageVector = Icons .Filled .Edit
56- onClick = { context.toast(" First Icon Clicked" ) }
57- }
58- icon {
59- imageVector = Icons .Filled .Delete
60- onClick = { context.toast(" Second Icon Clicked" ) }
61- }
62- icon {
63- label = " Third Example"
64- onClick = { context.toast(" Third Icon Clicked" ) }
65- }
66- }
67- defaults {
68- tint = Color .Red
69- }
70- overflowIcon {
71- tint = Color .Yellow
72- }
73- }
74- }
75- )
55+ OverflowMenu {
56+ shownIconsCount = 2
57+ icons {
58+ icon {
59+ imageVector = Icons .Filled .Edit
60+ onClick = { context.toast(" First Icon Clicked" ) }
61+ }
62+ icon {
63+ imageVector = Icons .Filled .Delete
64+ onClick = { context.toast(" Second Icon Clicked" ) }
65+ }
66+ icon {
67+ label = " Third Example"
68+ onClick = { context.toast(" Third Icon Clicked" ) }
69+ }
70+ }
71+ defaults {
72+ tint = Color .Red
73+ }
74+ overflowIcon {
75+ tint = Color .Yellow
7676 }
77- ) { }
77+ }
7878}
7979
8080@Composable
8181fun Sample2 () {
8282 var numberOfShownIcons by remember { mutableStateOf(3 ) }
83- Scaffold (
84- topBar = {
85- TopAppBar (
86- title = { Text (" Sample 2" ) },
87- actions = {
88- OverflowMenu {
89- shownIconsCount = numberOfShownIcons
90- icons {
91- icon {
92- onClick = { numberOfShownIcons = 3 }
93- tint = Color .Green
94- imageVector = Icons .Filled .Add
95- }
96- icon {
97- imageVector = Icons .Filled .Settings
98- }
99- icon {
100- onClick = { numberOfShownIcons = 1 }
101- tint = Color .Red
102- imageVector = Icons .Filled .Delete
103- }
104- icon {
105- label = " Fourth Example"
106- }
107- icon {
108- label = " Fifth Example"
109- }
110- }
111- defaults {
112- label = " Default Label"
113- }
114- }
115- }
116- )
83+ OverflowMenu {
84+ shownIconsCount = numberOfShownIcons
85+ icons {
86+ icon {
87+ onClick = { numberOfShownIcons = 3 }
88+ tint = Color .Green
89+ imageVector = Icons .Filled .Add
90+ }
91+ icon {
92+ imageVector = Icons .Filled .Settings
93+ }
94+ icon {
95+ onClick = { numberOfShownIcons = 1 }
96+ tint = Color .Red
97+ imageVector = Icons .Filled .Delete
98+ }
99+ icon {
100+ label = " Fourth Example"
101+ }
102+ icon {
103+ label = " Fifth Example"
104+ }
117105 }
118- ) {}
106+ defaults {
107+ label = " Default Label"
108+ }
109+ }
119110}
120111
121112@Composable
122113fun Sample3 () {
123114 val context = LocalContext .current
124- Scaffold (
125- topBar = {
126- TopAppBar (
127- title = { Text (" Sample 3" ) },
128- actions = {
129- OverflowMenu {
130- shownIconsCount = 1
131- icons {
132- icon {
133- onClick = { context.toast(" Clicked" ) }
134- modifier = Modifier .rotate(30f )
135- enabled = true
136- imageVector = Icons .Filled .Favorite
137- label = " Example label"
138- contentDescription = " Sample Icon"
139- tint = Color .Cyan
140- }
141- }
142- }
143- }
144- )
115+ OverflowMenu {
116+ shownIconsCount = 1
117+ icons {
118+ icon {
119+ onClick = { context.toast(" Clicked" ) }
120+ modifier = Modifier .rotate(30f )
121+ enabled = true
122+ imageVector = Icons .Filled .Favorite
123+ label = " Example label"
124+ contentDescription = " Sample Icon"
125+ tint = Color .Cyan
126+ }
145127 }
146- ) { }
128+ }
147129}
0 commit comments