@@ -18,10 +18,7 @@ import androidx.compose.material3.MaterialTheme
1818import androidx.compose.material3.Slider
1919import androidx.compose.material3.Surface
2020import androidx.compose.material3.Text
21- import androidx.compose.runtime.getValue
22- import androidx.compose.runtime.mutableStateOf
23- import androidx.compose.runtime.remember
24- import androidx.compose.runtime.setValue
21+ import androidx.compose.runtime.*
2522import androidx.compose.ui.Modifier
2623import androidx.compose.ui.graphics.Color
2724import androidx.compose.ui.graphics.ImageBitmap
@@ -45,146 +42,153 @@ class MainActivity : ComponentActivity() {
4542 modifier = Modifier .fillMaxSize(),
4643 color = MaterialTheme .colorScheme.background
4744 ) {
45+ RatingbarDemo ()
4846
49- var rating by remember { mutableStateOf(3.7f ) }
50- var rating2 by remember { mutableStateOf(3.7f ) }
51- var rating3 by remember { mutableStateOf(2.3f ) }
52- var rating4 by remember { mutableStateOf(4.5f ) }
53- var rating5 by remember { mutableStateOf(1.7f ) }
54- var rating6 by remember { mutableStateOf(5f ) }
55-
56- val imageBackground = ImageBitmap .imageResource(id = R .drawable.star_background)
57- val imageForeground = ImageBitmap .imageResource(id = R .drawable.star_foreground)
58-
59- Column (modifier = Modifier .fillMaxSize()) {
60- RatingBar (
61- rating = rating,
62- space = 2 .dp,
63- imageBackground = imageBackground,
64- imageForeground = imageForeground,
65- animationEnabled = false ,
66- gestureEnabled = true ,
67- itemSize = 60 .dp
68- ) {
69- rating = it
70- }
71-
72- Text (
73- " Rating: $rating " ,
74- fontSize = 16 .sp,
75- color = MaterialTheme .colorScheme.primary
76- )
77-
78- val purple500 = Color (0xff9C27B0 )
79-
80- RatingBar (
81- rating = rating2,
82- painterBackground = painterResource(id = R .drawable.star_background),
83- painterForeground = painterResource(id = R .drawable.star_foreground),
84- animationEnabled = false ,
85- gestureEnabled = false ,
86- tint = purple500,
87- shimmer = Shimmer (
88- colors = listOf (
89- purple500.copy(.9f ),
90- purple500.copy(.3f ),
91- purple500.copy(.9f )
92- )
93- ),
94- itemSize = 60 .dp
95- ) {
96- rating2 = it
97- }
98-
99- Slider (
100- value = rating2,
101- onValueChange = { rating2 = it },
102- valueRange = 0f .. 5f
103- )
104-
105- Text (
106- " Rating: $rating2 " ,
107- fontSize = 16 .sp,
108- color = MaterialTheme .colorScheme.primary
109- )
110-
111- RatingBar (
112- rating = rating3,
113- painterBackground = painterResource(id = R .drawable.star_background),
114- painterForeground = painterResource(id = R .drawable.star_foreground),
115- tint = Color (0xff795548 ),
116- animationEnabled = true ,
117- itemSize = 60 .dp
118- ) {
119- rating3 = it
120- }
121-
122- val pink500 = Color (0xffE91E63 )
123- RatingBar (
124- rating = rating4,
125- space = 2 .dp,
126- imageVectorBackground = Icons .Default .FavoriteBorder ,
127- imageVectorForeground = Icons .Default .Favorite ,
128- shimmer = Shimmer (
129- color = pink500,
130- animationSpec = infiniteRepeatable(
131- animation = tween(durationMillis = 1000 , easing = LinearEasing ),
132- repeatMode = RepeatMode .Reverse
133- )
134- ),
135- tint = pink500,
136- itemSize = 40 .dp
137- ) {
138- rating4 = it
139- }
140-
141- RatingBar (
142- rating = rating5,
143- space = 2 .dp,
144- imageVectorBackground = ImageVector .vectorResource(id = R .drawable.outline_wb_cloudy_24),
145- imageVectorForeground = ImageVector .vectorResource(id = R .drawable.baseline_wb_cloudy_24),
146- tint = Color (0xff2196F3 ),
147- itemSize = 60 .dp
148- ) {
149- rating5 = it
150- }
151-
152- RatingBar (
153- rating = rating6,
154- imageVectorBackground = ImageVector .vectorResource(id = R .drawable.twotone_person_24),
155- imageVectorForeground = ImageVector .vectorResource(id = R .drawable.baseline_person_24),
156- tint = Color (0xff795548 ),
157- itemSize = 40 .dp
158- ) {
159- rating6 = it
160- }
161-
162- RatingBar (
163- rating = 4.5f ,
164- space = 2 .dp,
165- itemCount = 10 ,
166- imageBackground = imageBackground,
167- imageForeground = imageForeground,
168- shimmer = Shimmer ()
169- )
170- Spacer (modifier= Modifier .height(10 .dp))
171-
172- RatingBar (
173- rating = 8.3f ,
174- space = 4 .dp,
175- itemCount = 10 ,
176- imageBackground = imageBackground,
177- imageForeground = imageForeground,
178- shimmer = Shimmer (
179- animationSpec = infiniteRepeatable(
180- animation = tween(durationMillis = 3000 , easing = LinearEasing ),
181- repeatMode = RepeatMode .Restart
182- )
183- )
184- )
185- }
18647 }
18748 }
18849 }
18950 }
19051}
52+
53+ @Composable
54+ private fun RatingbarDemo () {
55+ Column (modifier = Modifier .fillMaxSize()) {
56+ var rating by remember { mutableStateOf(3.7f ) }
57+ var rating2 by remember { mutableStateOf(3.7f ) }
58+ var rating3 by remember { mutableStateOf(2.3f ) }
59+ var rating4 by remember { mutableStateOf(4.5f ) }
60+ var rating5 by remember { mutableStateOf(1.7f ) }
61+ var rating6 by remember { mutableStateOf(5f ) }
62+
63+ val imageBackground = ImageBitmap .imageResource(id = R .drawable.star_background)
64+ val imageForeground = ImageBitmap .imageResource(id = R .drawable.star_foreground)
65+
66+ Column (modifier = Modifier .fillMaxSize()) {
67+ RatingBar (
68+ rating = rating,
69+ space = 2 .dp,
70+ imageBackground = imageBackground,
71+ imageForeground = imageForeground,
72+ animationEnabled = false ,
73+ gestureEnabled = true ,
74+ itemSize = 60 .dp
75+ ) {
76+ rating = it
77+ }
78+
79+ Text (
80+ " Rating: $rating " ,
81+ fontSize = 16 .sp,
82+ color = MaterialTheme .colorScheme.primary
83+ )
84+
85+ val purple500 = Color (0xff9C27B0 )
86+
87+ RatingBar (
88+ rating = rating2,
89+ painterBackground = painterResource(id = R .drawable.star_background),
90+ painterForeground = painterResource(id = R .drawable.star_foreground),
91+ animationEnabled = false ,
92+ gestureEnabled = false ,
93+ tint = purple500,
94+ shimmer = Shimmer (
95+ colors = listOf (
96+ purple500.copy(.9f ),
97+ purple500.copy(.3f ),
98+ purple500.copy(.9f )
99+ )
100+ ),
101+ itemSize = 60 .dp
102+ ) {
103+ rating2 = it
104+ }
105+
106+ Slider (
107+ value = rating2,
108+ onValueChange = { rating2 = it },
109+ valueRange = 0f .. 5f
110+ )
111+
112+ Text (
113+ " Rating: $rating2 " ,
114+ fontSize = 16 .sp,
115+ color = MaterialTheme .colorScheme.primary
116+ )
117+
118+ RatingBar (
119+ rating = rating3,
120+ painterBackground = painterResource(id = R .drawable.star_background),
121+ painterForeground = painterResource(id = R .drawable.star_foreground),
122+ tint = Color (0xff795548 ),
123+ animationEnabled = true ,
124+ itemSize = 60 .dp
125+ ) {
126+ rating3 = it
127+ }
128+
129+ val pink500 = Color (0xffE91E63 )
130+ RatingBar (
131+ rating = rating4,
132+ space = 2 .dp,
133+ imageVectorBackground = Icons .Default .FavoriteBorder ,
134+ imageVectorForeground = Icons .Default .Favorite ,
135+ shimmer = Shimmer (
136+ color = pink500,
137+ animationSpec = infiniteRepeatable(
138+ animation = tween(durationMillis = 1000 , easing = LinearEasing ),
139+ repeatMode = RepeatMode .Reverse
140+ )
141+ ),
142+ tint = pink500,
143+ itemSize = 40 .dp
144+ ) {
145+ rating4 = it
146+ }
147+
148+ RatingBar (
149+ rating = rating5,
150+ space = 2 .dp,
151+ imageVectorBackground = ImageVector .vectorResource(id = R .drawable.outline_wb_cloudy_24),
152+ imageVectorForeground = ImageVector .vectorResource(id = R .drawable.baseline_wb_cloudy_24),
153+ tint = Color (0xff2196F3 ),
154+ itemSize = 60 .dp
155+ ) {
156+ rating5 = it
157+ }
158+
159+ RatingBar (
160+ rating = rating6,
161+ imageVectorBackground = ImageVector .vectorResource(id = R .drawable.twotone_person_24),
162+ imageVectorForeground = ImageVector .vectorResource(id = R .drawable.baseline_person_24),
163+ tint = Color (0xff795548 ),
164+ itemSize = 40 .dp
165+ ) {
166+ rating6 = it
167+ }
168+
169+ RatingBar (
170+ rating = 4.5f ,
171+ space = 2 .dp,
172+ itemCount = 10 ,
173+ imageBackground = imageBackground,
174+ imageForeground = imageForeground,
175+ shimmer = Shimmer ()
176+ )
177+ Spacer (modifier= Modifier .height(10 .dp))
178+
179+ RatingBar (
180+ rating = 8.3f ,
181+ space = 4 .dp,
182+ itemCount = 10 ,
183+ imageBackground = imageBackground,
184+ imageForeground = imageForeground,
185+ shimmer = Shimmer (
186+ animationSpec = infiniteRepeatable(
187+ animation = tween(durationMillis = 3000 , easing = LinearEasing ),
188+ repeatMode = RepeatMode .Restart
189+ )
190+ )
191+ )
192+ }
193+ }
194+ }
0 commit comments