@Composable
fun Button(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = ButtonDefaults.shape,
colors: ButtonColors = ButtonDefaults.buttonColors(),
elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
border: BorderStroke? = null,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable RowScope.() -> Unit
) {
val containerColor = colors.containerColor(enabled).value
val contentColor = colors.contentColor(enabled).value
val shadowElevation = elevation?.shadowElevation(enabled, interactionSource)?.value ?: 0.dp
val tonalElevation = elevation?.tonalElevation(enabled, interactionSource)?.value ?: 0.dp
Surface(
onClick = onClick,
modifier = modifier.semantics { role = Role.Button },
enabled = enabled,
shape = shape,
color = containerColor,
contentColor = contentColor,
tonalElevation = tonalElevation,
shadowElevation = shadowElevation,
border = border,
interactionSource = interactionSource
) {
CompositionLocalProvider(LocalContentColor provides contentColor) {
ProvideTextStyle(value = MaterialTheme.typography.labelLarge) {
Row(
Modifier
.defaultMinSize(
minWidth = ButtonDefaults.MinWidth,
minHeight = ButtonDefaults.MinHeight
)
.padding(contentPadding),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
content = content
)
}
}
}
}
Button
Android - Cómo escribir mensajes de registro
Cómo escribir mensajes de registro
La clase Log
te permite crear mensajes de registro que aparecerán en Logcat. Todos los mensajes de registro de Android tienen una etiqueta y una prioridad asociadas a ellos. La etiqueta de un mensaje de registro del sistema es una string breve que indica el componente del sistema a partir del cual se origina el mensaje.
Usa los siguientes métodos de acceso, ordenados de mayor a menor prioridad:
- Error:
Log.e(String, String)
- Advertencia:
Log.w(String, String)
- Información:
Log.i(String, String)
- Depuración:
Log.d(String, String)
- Verbosidad:
Log.v(String, String)
Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from AndroidManifest.xml
error: Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from AndroidManifest.xml
poner en gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Error: Unresolved reference
Android Studio no reconoce las variables.
solucion:
ir a build.gradle (Module)
borrar todo plugins{ } aparece al principio y puede tener 2 id
remplazar por
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Sobre android studio y como definir una interfaz
Los id se utilizan para que la clase R pueda revisar y encontrar cada elemento, ej: si tenemos un elemento, un TextView cuyo id se definió como...
android:id="@+id/tvMainTitle"el id es tvMainTitle, este id puede ser referenciado mediante...
R.id.tvMainTitle
de esta forma se puede hacer uso de sus propiedades...
Para acomodar el código de forma rápida en Windows o Linux meciante el atajo Ctrl+Alt+L, si no anda en la parte superior code > Reformat Code
Organización Lineal (LinearLayout)
orientation="vertical" de arriba hacia abajo
orientation="horizontal" de izquierda a derecha
dentro de un LinearLayout puede haber otro que tenga otra orientación
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"> <TextView
android:id="@+id/tvMainTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hola Mundo!"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/ic_filter_1_black_24dp"/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/ic_filter_2_black_24dp"/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/ic_filter_3_black_24dp"/>
</LinearLayout>
</LinearLayout>
Como podemos ver el "hola mundo" y el cuadrado verde están dentro del primer LinearLayout y los Vector Assets con los números 1, 2 y 3 están el el segundo LinearLayout con una orientación horizontal, en necesario poner su orientación.
Organizacion Relativa(RelativeLayout)
los elementos se organizan dependiendo de otros elementos
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <ImageView
android:layout_width="240dp"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="@drawable/rojo" /> <ImageView
android:id="@+id/ivMainVerde"
android:layout_width="150dp"
android:layout_height="370dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:src="@drawable/verde" /> <ImageView
android:layout_width="250dp"
android:layout_height="130dp"
android:layout_below="@+id/ivMainVerde"
android:src="@drawable/azul" /> <ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:src="@drawable/rosado" />
</RelativeLayout>
Como se puede ver los tags de align definen el lugar que les corresponde a los elementos, en el caso del azul lo hace con respecto al verde mediante el id que éste debe poseer, los alignParent son con respecto a la vista, los que no, con respecto a otro elemento.
FrameLayout
cuando es requerido que la aplicación no ocupe toda la pantalla, o que en un cierto lugar aparezca una imagen, es decir que crecerá tanto como uno quiera.
Resulta muy versátil, porque permite poner vistas de forma dinámica así podemos reservar una vista para que entre y salga constantemente, también permite poner una imagen sobre otra sin problemas, es recomendable que tenga un solo hijo.
Layouts externos: ConstraintLayout
-
https://youtube.com/shorts/6mLN39EE5hE?si=ptldeUKRZ9jqJdvK