0% found this document useful (0 votes)
9 views8 pages

Kotlin Android Login with Jetpack Compose

The document contains Kotlin code for an Android login application using Jetpack Compose. It includes the implementation of a main activity with navigation for login, registration, and home screens, along with UI components like buttons, text fields, and cards. The code demonstrates a gradient background, user input handling, and navigation logic between different screens.

Uploaded by

Gustavo Henrique
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Kotlin Android Login with Jetpack Compose

The document contains Kotlin code for an Android login application using Jetpack Compose. It includes the implementation of a main activity with navigation for login, registration, and home screens, along with UI components like buttons, text fields, and cards. The code demonstrates a gradient background, user input handling, and navigation logic between different screens.

Uploaded by

Gustavo Henrique
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

1 | package [Link]
2|
3 | import [Link]
4 | import [Link]
5 | import [Link]
6 | import [Link]
7 | import [Link]
8 | import [Link]
9 | import [Link]
10 | import [Link]
11 | import [Link]
12 | import [Link]
13 | import [Link]
14 | import [Link]
15 | import [Link]
16 | import [Link]
17 | import [Link]
18 | import [Link]
19 | import [Link]
20 | import [Link]
21 | import [Link]
22 | import [Link]
23 | import [Link]
24 | import [Link]
25 | import [Link]
26 | import [Link]
27 | import [Link]
28 | import [Link]
29 | import [Link]
30 | import [Link].material3.ExperimentalMaterial3Api
31 | import [Link]
32 | import [Link]
33 | import [Link]
34 | import [Link]
35 | import [Link]
36 | import [Link]
37 | import [Link]
38 | import [Link]
39 | import [Link]
40 | import [Link]
41 | import [Link]
42 | import [Link]
43 | import [Link]
44 | import [Link]
45 | import [Link]
46 | import [Link]
47 | import [Link]
48 | import [Link]
49 | import [Link]
50 | import [Link]
51 | import [Link]
52 | import [Link]
53 | import [Link]
54 | import [Link]
55 | import [Link]
56 | import [Link]
57 | import [Link]
58 | import [Link]

Página 1
Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

59 | import [Link]
60 | import [Link]
61 | import [Link]
62 |
63 | class MainActivity : ComponentActivity() {
64 | @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
65 | override fun onCreate(savedInstanceState: Bundle?) {
66 | [Link](savedInstanceState)
67 | enableEdgeToEdge()
68 | setContent {
69 | AppLoginTheme {
70 | val navController = rememberNavController()
71 | Scaffold(modifier = [Link]()) {
72 | NavHost(navController = navController, startDestinatio
n = "login") {
73 | composable("login") {
74 | LoginScreen(
75 | onLogin = { userName ->
76 | [Link]("home/${userNam
[Link] { "Convidado" }}")
77 | },
78 | onRegisterClick = {
79 | [Link]("register")
80 | }
81 | )
82 | }
83 | composable("register") {
84 | RegisterScreen(
85 | onRegisterComplete = {
86 | [Link]()
87 | }
88 | )
89 | }
90 | composable(
91 | "home/{userName}",
92 | arguments = listOf(navArgument("userName") {
93 | type = [Link]
94 | })
95 | ) { backStackEntry ->
96 | val userName =
97 | [Link]?.getString("userN
ame") ?: "Usuário"
98 | HomeScreen(userName = userName)
99 | }
100 | }
101 | }
102 | }
103 | }
104 | }
105 | }
106 |
107 | @Composable
108 | fun LoginScreen(onLogin: (String) -> Unit, onRegisterClick: () -> Unit) {
109 | var user by remember { mutableStateOf("") }
110 | var password by remember { mutableStateOf("") }
111 |
112 | // Gradiente de fundo vertical
113 | val gradient = [Link](

Página 2
Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

114 | colors = listOf(Color(0xFF2196F3), Color(0xFF1976D2))


115 | )
116 |
117 | Box(
118 | modifier = Modifier
119 | .fillMaxSize()
120 | .background(brush = gradient),
121 | contentAlignment = [Link]
122 | ){
123 | // Card com sombra e arredondamento
124 | Card(
125 | modifier = Modifier
126 | .padding([Link])
127 | .fillMaxWidth(0.9f)
128 | .wrapContentHeight(),
129 | shape = RoundedCornerShape([Link]),
130 | elevation = [Link]([Link])
131 | ){
132 | Column(
133 | horizontalAlignment = [Link],
134 | modifier = Modifier
135 | .padding([Link])
136 | ){
137 | // Logo (substitua pela sua imagem)
138 | Image(
139 | painter = painterResource(id = [Link].ic_logo),
140 | contentDescription = "Logo",
141 | modifier = Modifier
142 | .height([Link])
143 | .padding(bottom = [Link])
144 | )
145 |
146 | Text(
147 | text = "App Login",
148 | fontSize = [Link],
149 | fontWeight = [Link],
150 | color = Color(0xFF1976D2)
151 | )
152 |
153 | Spacer(modifier = [Link]([Link]))
154 |
155 | // Campo de usuário
156 | OutlinedTextField(
157 | value = user,
158 | onValueChange = { user = it },
159 | label = { Text("Usuário") },
160 | modifier = [Link]()
161 | )
162 |
163 | Spacer(modifier = [Link]([Link]))
164 |
165 | // Campo de senha
166 | OutlinedTextField(
167 | value = password,
168 | onValueChange = { password = it },
169 | label = { Text("Senha") },
170 | visualTransformation = PasswordVisualTransformation(),
171 | keyboardOptions = KeyboardOptions(keyboardType = Keybo

Página 3
Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

[Link]),
172 | modifier = [Link]()
173 | )
174 |
175 | Spacer(modifier = [Link]([Link]))
176 |
177 | // Botão Logar
178 | Button(
179 | onClick = {
180 | onLogin(user)
181 | },
182 | modifier = Modifier
183 | .fillMaxWidth()
184 | .height([Link]),
185 | colors = [Link](
186 | containerColor = Color(0xFF1976D2),
187 | contentColor = [Link]
188 | ),
189 | shape = RoundedCornerShape([Link])
190 | ){
191 | Text("Logar", fontSize = [Link])
192 | }
193 |
194 | Spacer(modifier = [Link]([Link]))
195 |
196 | // Botão Esqueceu a senha
197 | TextButton(onClick = {
198 | onRegisterClick()
199 | }) {
200 | Text(
201 | "Esqueceu a senha?",
202 | color = Color(0xFF1976D2),
203 | fontSize = [Link]
204 | )
205 | }
206 | }
207 | }
208 | }
209 | }
210 |
211 | @Composable
212 | fun RegisterScreen(onRegisterComplete: () -> Unit) {
213 | var username by remember { mutableStateOf("") }
214 | var email by remember { mutableStateOf("") }
215 | var password by remember { mutableStateOf("") }
216 | var confirmPassword by remember { mutableStateOf("") }
217 |
218 | val gradient = [Link](
219 | colors = listOf(Color(0xFF2196F3), Color(0xFF1976D2))
220 | )
221 |
222 | Box(
223 | modifier = Modifier
224 | .fillMaxSize()
225 | .background(brush = gradient),
226 | contentAlignment = [Link]
227 | ){
228 | Card(

Página 4
Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

229 | modifier = Modifier


230 | .padding([Link])
231 | .fillMaxWidth(0.9f)
232 | .wrapContentHeight(),
233 | shape = RoundedCornerShape([Link]),
234 | elevation = [Link]([Link])
235 | ){
236 | Column(
237 | horizontalAlignment = [Link],
238 | modifier = [Link]([Link])
239 | ){
240 | Image(
241 | painter = painterResource(id = [Link].ic_logo),
242 | contentDescription = "Logo",
243 | modifier = Modifier
244 | .height([Link])
245 | .padding(bottom = [Link])
246 | )
247 |
248 | Text(
249 | text = "Cadastro",
250 | fontSize = [Link],
251 | fontWeight = [Link],
252 | color = Color(0xFF1976D2)
253 | )
254 |
255 | Spacer(modifier = [Link]([Link]))
256 |
257 | OutlinedTextField(
258 | value = username,
259 | onValueChange = { username = it },
260 | label = { Text("Nome de usuário") },
261 | modifier = [Link]()
262 | )
263 |
264 | Spacer(modifier = [Link]([Link]))
265 |
266 | OutlinedTextField(
267 | value = email,
268 | onValueChange = { email = it },
269 | label = { Text("E-mail") },
270 | keyboardOptions = KeyboardOptions(keyboardType = Keybo
[Link]),
271 | modifier = [Link]()
272 | )
273 |
274 | Spacer(modifier = [Link]([Link]))
275 |
276 | OutlinedTextField(
277 | value = password,
278 | onValueChange = { password = it },
279 | label = { Text("Senha") },
280 | visualTransformation = PasswordVisualTransformation(),
281 | keyboardOptions = KeyboardOptions(keyboardType = Keybo
[Link]),
282 | modifier = [Link]()
283 | )
284 |

Página 5
Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

285 | Spacer(modifier = [Link]([Link]))


286 |
287 | OutlinedTextField(
288 | value = confirmPassword,
289 | onValueChange = { confirmPassword = it },
290 | label = { Text("Confirmar senha") },
291 | visualTransformation = PasswordVisualTransformation(),
292 | keyboardOptions = KeyboardOptions(keyboardType = Keybo
[Link]),
293 | modifier = [Link]()
294 | )
295 |
296 | Spacer(modifier = [Link]([Link]))
297 |
298 | Button(
299 | onClick = {
300 | onRegisterComplete()
301 | },
302 | modifier = Modifier
303 | .fillMaxWidth()
304 | .height([Link]),
305 | colors = [Link](
306 | containerColor = Color(0xFF1976D2),
307 | contentColor = [Link]
308 | ),
309 | shape = RoundedCornerShape([Link])
310 | ){
311 | Text("Cadastrar", fontSize = [Link])
312 | }
313 |
314 | Spacer(modifier = [Link]([Link]))
315 |
316 | TextButton(onClick = {
317 | onRegisterComplete()
318 | }) {
319 | Text(
320 | "Já tem uma conta? Faça login",
321 | color = Color(0xFF1976D2),
322 | fontSize = [Link]
323 | )
324 | }
325 | }
326 | }
327 | }
328 | }
329 |
330 | @Composable
331 | fun HomeScreen(userName: String = "Usuário") {
332 | var menuExpanded by remember { mutableStateOf(false) }
333 |
334 | // Gradiente de fundo vertical
335 | val gradient = [Link](
336 | colors = listOf(Color(0xFF2196F3), Color(0xFF1976D2))
337 | )
338 |
339 | Box(
340 | modifier = Modifier
341 | .fillMaxSize()

Página 6
Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

342 | .background(brush = gradient),


343 | contentAlignment = [Link]
344 | ){
345 | Column(
346 | horizontalAlignment = [Link],
347 | modifier = Modifier
348 | .fillMaxWidth()
349 | .padding([Link])
350 | ){
351 | // Botão de menu (três pontos)
352 | Box {
353 | IconButton(onClick = { menuExpanded = true }) {
354 | Icon(
355 | imageVector = [Link],
356 | contentDescription = "Menu",
357 | tint = [Link]
358 | )
359 | }
360 |
361 | DropdownMenu(
362 | expanded = menuExpanded,
363 | onDismissRequest = { menuExpanded = false }
364 | ){
365 | DropdownMenuItem(
366 | text = { Text("Cadastrar Produto") },
367 | onClick = {
368 | menuExpanded = false
369 | // ação de navegação ou lógica
370 | }
371 | )
372 | DropdownMenuItem(
373 | text = { Text("Listar Produto") },
374 | onClick = {
375 | menuExpanded = false
376 | // ação de navegação ou lógica
377 | }
378 | )
379 | DropdownMenuItem(
380 | text = { Text("Perfil de $userName") },
381 | onClick = {
382 | menuExpanded = false
383 | // ação de navegação ou lógica
384 | }
385 | )
386 | Divider()
387 | DropdownMenuItem(
388 | text = { Text("Deslogar") },
389 | onClick = {
390 | menuExpanded = false
391 | // ação de logout
392 | }
393 | )
394 | }
395 | }
396 | }
397 |
398 | // Card central com boas-vindas
399 | Card(

Página 7
Código Kotlin — Android Login (Jetpack Compose) Gerado em 2025-08-11 17:03

400 | modifier = Modifier


401 | .padding(top = [Link], bottom = [Link])
402 | .fillMaxWidth(0.9f)
403 | .fillMaxSize(),
404 | shape = RoundedCornerShape([Link]),
405 | elevation = [Link]([Link])
406 | ){
407 | Column(
408 | horizontalAlignment = [Link],
409 | modifier = [Link]([Link])
410 | ){
411 | Image(
412 | painter = painterResource(id = [Link].ic_logo),
413 | contentDescription = "Logo",
414 | modifier = Modifier
415 | .height([Link])
416 | .padding(bottom = [Link])
417 | )
418 |
419 | Text(
420 | text = "Bem-vindo, $userName!",
421 | fontSize = [Link],
422 | fontWeight = [Link],
423 | color = Color(0xFF1976D2),
424 | textAlign = [Link]
425 | )
426 |
427 | Spacer(modifier = [Link]([Link]))
428 |
429 | Text(
430 | text = "Use o menu no canto superior direito para nave
gar.",
431 | fontSize = [Link],
432 | color = [Link],
433 | textAlign = [Link]
434 | )
435 | }
436 | }
437 | }
438 | }

Página 8

You might also like