Skip to content

Instantly share code, notes, and snippets.

@SalcidoJesus
Last active September 25, 2024 15:19
Show Gist options
  • Save SalcidoJesus/f4039b9cebb32b197e1d045f457a56d2 to your computer and use it in GitHub Desktop.
Save SalcidoJesus/f4039b9cebb32b197e1d045f457a56d2 to your computer and use it in GitHub Desktop.
Código para la creación de un menú utilizando Jetpack Compose
import androidx.compose.foundation.Image
import com.example.jmsa.R
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CardElevation
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.jmsa.ui.theme.Typography
// jetpack compose
@Preview( showSystemUi = true, locale = "en" )
@Composable
fun PantallaMenu () {
PantallaCompleta()
}
@Composable
fun PantallaCompleta() {
Column(
modifier = Modifier.verticalScroll( rememberScrollState() )
.padding( bottom = 50.dp )
) {
TextoTitulo()
ListadoTarjetas()
}
}
@Composable
fun TextoTitulo() {
Text(
stringResource( R.string.nombre_panel ),
modifier = Modifier
.fillMaxWidth()
.padding( top = 20.dp, bottom = 30.dp ),
style = Typography.titleLarge
)
}
@OptIn(ExperimentalLayoutApi::class)
@Composable
fun ListadoTarjetas() {
FlowRow (
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalArrangement = Arrangement.spacedBy( 30.dp )
) {
Tarjeta("Perfil2", R.drawable.user)
Tarjeta("Eventos", R.drawable.calendar)
Tarjeta("Staffs", R.drawable.group)
Tarjeta("Attendence", R.drawable.checklist)
Tarjeta("Chatbox", R.drawable.chat)
Tarjeta("GradeSheet", R.drawable.bar_chart)
Tarjeta("Gallery", R.drawable.gallery)
Tarjeta("Fees details", R.drawable.dollar)
}
}
@Composable
fun Tarjeta( titulo: String, imagen: Int ) {
Card (
modifier = Modifier
.fillMaxWidth( .35f )
.size( 120.dp ),
onClick = { },
elevation = CardDefaults.cardElevation(
defaultElevation = 10.dp,
),
) {
// este es el contenido de la tarjeta
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
Column(
horizontalAlignment =Alignment.CenterHorizontally
) {
Image(
painter = painterResource( imagen ),
contentDescription = "",
modifier = Modifier
.size(50.dp)
)
Spacer( modifier = Modifier.size( 10.dp ) )
Text(titulo)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment