Hola amigos 👋 Bienvenidos a un nuevo tutorial de Universo Android. Hoy aprenderemos todo sobre los Botones (Button) en Android, explorando los diferentes tipos, estilos personalizados, eventos de click y las mejores prácticas para crear interfaces interactivas y profesionales.
Al finalizar este tutorial tendrás una aplicación que incluirá:
- Button tradicional y sus variantes
- ImageButton con iconos
- FloatingActionButton (FAB)
- ToggleButton y Switch
- Estilos personalizados con XML y Material Design
- Click Listeners con diferentes métodos
- Botones con estados (enabled, disabled, pressed)
- Animaciones y efectos visuales
🟩 1. ¿Qué es un Button en Android?
El Button es un componente fundamental de la interfaz de usuario que permite a los usuarios ejecutar acciones mediante toques o clics. Android ofrece varios tipos de botones, cada uno optimizado para diferentes casos de uso.
🟩 2. Tipos de Botones en Android
Android proporciona varios tipos de botones:
- Button: Botón estándar con texto
- ImageButton: Botón con imagen sin texto
- FloatingActionButton (FAB): Botón flotante de Material Design
- ToggleButton: Botón de dos estados (ON/OFF)
- Switch: Interruptor deslizante
- RadioButton: Botón de selección única
- CheckBox: Casilla de verificación
🟩 3. Crear el Proyecto en Android Studio
Creamos un nuevo proyecto en Android Studio con Empty Activity.
🟩 4. Agregar Dependencias de Material Design
Abre el archivo build.gradle (Module: app) y agrega:
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}Sincroniza el proyecto después de agregar las dependencias.
🟩 5. Diseño XML con Diferentes Tipos de Botones
Crea un archivo llamado:
📄 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- TÃtulo Principal -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Botones Estándar"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#2196F3"
android:layout_marginBottom="16dp" />
<!-- Button Normal -->
<Button
android:id="@+id/btnNormal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Botón Normal"
android:textSize="16sp"
android:layout_marginTop="8dp" />
<!-- Button con Icono -->
<Button
android:id="@+id/btnWithIcon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Botón con Icono"
android:drawableLeft="@android:drawable/ic_dialog_email"
android:drawablePadding="8dp"
android:textSize="16sp"
android:layout_marginTop="8dp" />
<!-- Button Deshabilitado -->
<Button
android:id="@+id/btnDisabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Botón Deshabilitado"
android:enabled="false"
android:textSize="16sp"
android:layout_marginTop="8dp" />
<!-- Separador -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#CCCCCC"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" />
<!-- TÃtulo: Material Design Buttons -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Material Design Buttons"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#4CAF50"
android:layout_marginBottom="16dp" />
<!-- Material Button Filled -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnMaterialFilled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Material Filled"
app:cornerRadius="8dp"
style="@style/Widget.MaterialComponents.Button"
android:layout_marginTop="8dp" />
<!-- Material Button Outlined -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnMaterialOutlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Material Outlined"
app:cornerRadius="8dp"
app:strokeColor="#2196F3"
app:strokeWidth="2dp"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_marginTop="8dp" />
<!-- Material Button Text -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnMaterialText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Material Text"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_marginTop="8dp" />
<!-- Material Button con Icono -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnMaterialIcon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Con Icono Material"
app:icon="@android:drawable/ic_menu_camera"
app:iconGravity="textStart"
app:cornerRadius="8dp"
android:layout_marginTop="8dp" />
<!-- Separador -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#CCCCCC"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" />
<!-- TÃtulo: Image Buttons -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image Buttons"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#FF9800"
android:layout_marginBottom="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<!-- ImageButton 1 -->
<ImageButton
android:id="@+id/btnImage1"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@android:drawable/ic_menu_camera"
android:background="@drawable/round_button"
android:scaleType="centerInside"
android:layout_margin="8dp"
android:contentDescription="Cámara" />
<!-- ImageButton 2 -->
<ImageButton
android:id="@+id/btnImage2"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@android:drawable/ic_menu_gallery"
android:background="@drawable/round_button"
android:scaleType="centerInside"
android:layout_margin="8dp"
android:contentDescription="GalerÃa" />
<!-- ImageButton 3 -->
<ImageButton
android:id="@+id/btnImage3"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@android:drawable/ic_menu_share"
android:background="@drawable/round_button"
android:scaleType="centerInside"
android:layout_margin="8dp"
android:contentDescription="Compartir" />
</LinearLayout>
<!-- Separador -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#CCCCCC"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" />
<!-- TÃtulo: Toggle Buttons -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle y Switch"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#E91E63"
android:layout_marginBottom="16dp" />
<!-- ToggleButton -->
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOn="Activado"
android:textOff="Desactivado"
android:layout_marginTop="8dp" />
<!-- Switch -->
<Switch
android:id="@+id/switchButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Notificaciones"
android:layout_marginTop="8dp" />
<!-- Material Switch -->
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/materialSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Modo Oscuro"
android:layout_marginTop="8dp" />
<!-- Separador -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#CCCCCC"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" />
<!-- TÃtulo: Botones Personalizados -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Botones Personalizados"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#9C27B0"
android:layout_marginBottom="16dp" />
<!-- Botón con Gradiente -->
<Button
android:id="@+id/btnGradient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Botón con Gradiente"
android:textColor="#FFFFFF"
android:background="@drawable/gradient_button"
android:textSize="16sp"
android:layout_marginTop="8dp" />
<!-- Botón Redondeado -->
<Button
android:id="@+id/btnRounded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Botón Redondeado"
android:textColor="#FFFFFF"
android:background="@drawable/rounded_button"
android:textSize="16sp"
android:layout_marginTop="8dp" />
<!-- Botón con Borde -->
<Button
android:id="@+id/btnBorder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Botón con Borde"
android:textColor="#2196F3"
android:background="@drawable/border_button"
android:textSize="16sp"
android:layout_marginTop="8dp" />
<!-- TextView para mostrar resultados -->
<TextView
android:id="@+id/txtResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Resultados aparecerán aquÃ"
android:textSize="16sp"
android:textColor="#000000"
android:padding="16dp"
android:background="#F5F5F5"
android:layout_marginTop="24dp" />
</LinearLayout>
</ScrollView>🟩 6. Crear Drawables para Botones Personalizados
Drawable 1: Botón Redondeado
Crea res/drawable/rounded_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#2196F3" />
<corners android:radius="24dp" />
<padding
android:left="16dp"
android:top="12dp"
android:right="16dp"
android:bottom="12dp" />
</shape>Drawable 2: Botón con Gradiente
Crea res/drawable/gradient_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FF5722"
android:endColor="#E91E63"
android:angle="45"
android:type="linear" />
<corners android:radius="16dp" />
<padding
android:left="16dp"
android:top="12dp"
android:right="16dp"
android:bottom="12dp" />
</shape>Drawable 3: Botón con Borde
Crea res/drawable/border_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<stroke
android:width="2dp"
android:color="#2196F3" />
<corners android:radius="8dp" />
<padding
android:left="16dp"
android:top="12dp"
android:right="16dp"
android:bottom="12dp" />
</shape>Drawable 4: Botón Circular
Crea res/drawable/round_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#4CAF50" />
<size
android:width="64dp"
android:height="64dp" />
</shape>🟩 7. Crear Selector para Estados del Botón
Crea res/drawable/button_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Estado Presionado -->
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#1976D2" />
<corners android:radius="8dp" />
</shape>
</item>
<!-- Estado Deshabilitado -->
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="#CCCCCC" />
<corners android:radius="8dp" />
</shape>
</item>
<!-- Estado Normal -->
<item>
<shape android:shape="rectangle">
<solid android:color="#2196F3" />
<corners android:radius="8dp" />
</shape>
</item>
</selector>🟩 8. Lógica Java con Click Listeners
📄 MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.switchmaterial.SwitchMaterial;
public class MainActivity extends AppCompatActivity {
Button btnNormal, btnWithIcon, btnDisabled, btnGradient, btnRounded, btnBorder;
MaterialButton btnMaterialFilled, btnMaterialOutlined, btnMaterialText, btnMaterialIcon;
ImageButton btnImage1, btnImage2, btnImage3;
ToggleButton toggleButton;
Switch switchButton;
SwitchMaterial materialSwitch;
TextView txtResult;
int clickCount = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Inicializar vistas
initializeViews();
// Configurar Click Listeners - Método 1: Lambda
setupLambdaListeners();
// Configurar Click Listeners - Método 2: Clase Anónima
setupAnonymousListeners();
// Configurar Click Listeners - Método 3: Implementar Interface
setupInterfaceListeners();
// Configurar Toggle y Switch
setupToggleAndSwitch();
// Configurar Image Buttons
setupImageButtons();
}
private void initializeViews() {
// Botones estándar
btnNormal = findViewById(R.id.btnNormal);
btnWithIcon = findViewById(R.id.btnWithIcon);
btnDisabled = findViewById(R.id.btnDisabled);
btnGradient = findViewById(R.id.btnGradient);
btnRounded = findViewById(R.id.btnRounded);
btnBorder = findViewById(R.id.btnBorder);
// Material Buttons
btnMaterialFilled = findViewById(R.id.btnMaterialFilled);
btnMaterialOutlined = findViewById(R.id.btnMaterialOutlined);
btnMaterialText = findViewById(R.id.btnMaterialText);
btnMaterialIcon = findViewById(R.id.btnMaterialIcon);
// Image Buttons
btnImage1 = findViewById(R.id.btnImage1);
btnImage2 = findViewById(R.id.btnImage2);
btnImage3 = findViewById(R.id.btnImage3);
// Toggle y Switch
toggleButton = findViewById(R.id.toggleButton);
switchButton = findViewById(R.id.switchButton);
materialSwitch = findViewById(R.id.materialSwitch);
// TextView resultado
txtResult = findViewById(R.id.txtResult);
}
// MÉTODO 1: Click Listener con Lambda (Java 8+)
private void setupLambdaListeners() {
btnNormal.setOnClickListener(v -> {
clickCount++;
updateResult("Botón Normal clickeado - Total: " + clickCount);
});
btnMaterialFilled.setOnClickListener(v ->
updateResult("Material Filled clickeado")
);
}
// MÉTODO 2: Click Listener con Clase Anónima
private void setupAnonymousListeners() {
btnWithIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateResult("Botón con Icono clickeado");
}
});
btnGradient.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateResult("Botón con Gradiente clickeado");
}
});
}
// MÉTODO 3: Click Listener implementando Interface
private void setupInterfaceListeners() {
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == R.id.btnMaterialOutlined) {
updateResult("Material Outlined clickeado");
} else if (v.getId() == R.id.btnMaterialText) {
updateResult("Material Text clickeado");
} else if (v.getId() == R.id.btnMaterialIcon) {
updateResult("Material con Icono clickeado");
} else if (v.getId() == R.id.btnRounded) {
updateResult("Botón Redondeado clickeado");
} else if (v.getId() == R.id.btnBorder) {
updateResult("Botón con Borde clickeado");
}
}
};
btnMaterialOutlined.setOnClickListener(listener);
btnMaterialText.setOnClickListener(listener);
btnMaterialIcon.setOnClickListener(listener);
btnRounded.setOnClickListener(listener);
btnBorder.setOnClickListener(listener);
}
// MÉTODO 4: Click desde XML (onClick attribute)
public void onButtonClick(View view) {
updateResult("Método onClick desde XML");
}
private void setupToggleAndSwitch() {
// ToggleButton
toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String status = isChecked ? "Activado" : "Desactivado";
updateResult("Toggle Button: " + status);
}
});
// Switch
switchButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
String status = isChecked ? "Notificaciones ON" : "Notificaciones OFF";
updateResult(status);
Toast.makeText(this, status, Toast.LENGTH_SHORT).show();
});
// Material Switch
materialSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
String status = isChecked ? "Modo Oscuro Activado" : "Modo Oscuro Desactivado";
updateResult(status);
// Cambiar color de fondo como ejemplo
if (isChecked) {
findViewById(android.R.id.content).setBackgroundColor(0xFF424242);
} else {
findViewById(android.R.id.content).setBackgroundColor(0xFFFFFFFF);
}
});
}
private void setupImageButtons() {
btnImage1.setOnClickListener(v -> {
updateResult("Cámara clickeada");
Toast.makeText(this, "Abrir Cámara", Toast.LENGTH_SHORT).show();
});
btnImage2.setOnClickListener(v -> {
updateResult("GalerÃa clickeada");
Toast.makeText(this, "Abrir GalerÃa", Toast.LENGTH_SHORT).show();
});
btnImage3.setOnClickListener(v -> {
updateResult("Compartir clickeado");
Toast.makeText(this, "Compartir contenido", Toast.LENGTH_SHORT).show();
});
}
// MÉTODO 5: Long Click Listener
private void setupLongClickListener() {
btnNormal.setOnLongClickListener(v -> {
updateResult("Long Click detectado en Botón Normal");
Toast.makeText(this, "Mantuviste presionado el botón", Toast.LENGTH_SHORT).show();
return true; // true = evento consumido
});
}
// MÉTODO 6: Habilitar/Deshabilitar botón dinámicamente
private void toggleButtonState() {
if (btnDisabled.isEnabled()) {
btnDisabled.setEnabled(false);
btnDisabled.setText("Deshabilitado");
} else {
btnDisabled.setEnabled(true);
btnDisabled.setText("Habilitado");
}
}
private void updateResult(String message) {
txtResult.setText(message);
}
}🟩 9. FloatingActionButton (FAB)
Agrega un FAB al layout:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Tu contenido aquà -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add"
app:backgroundTint="#4CAF50"
app:tint="#FFFFFF" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>En Java:
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(v -> {
Toast.makeText(this, "FAB clickeado", Toast.LENGTH_SHORT).show();
});🟩 10. Crear Estilos Reutilizables
Crea un archivo res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Estilo para Botón Principal -->
<style name="PrimaryButton" parent="Widget.MaterialComponents.Button">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#FFFFFF</item>
<item name="backgroundTint">#2196F3</item>
<item name="cornerRadius">8dp</item>
<item name="android:layout_marginTop">8dp</item>
</style>
<!-- Estilo para Botón Secundario -->
<style name="SecondaryButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#2196F3</item>
<item name="strokeColor">#2196F3</item>
<item name="strokeWidth">2dp</item>
<item name="cornerRadius">8dp</item>
<item name="android:layout_marginTop">8dp</item>
</style>
<!-- Estilo para Botón de Texto -->
<style name="TextButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#2196F3</item>
<item name="android:layout_marginTop">8dp</item>
</style>
<!-- Estilo para Botón Peligroso -->
<style name="DangerButton" parent="Widget.MaterialComponents.Button">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#FFFFFF</item>
<item name="backgroundTint">#F44336</item>
<item name="cornerRadius">8dp</item>
<item name="android:layout_marginTop">8dp</item>
</style>
</resources>Aplicar estilos en XML:
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Botón Primario"
style="@style/PrimaryButton" />🟩 11. Propiedades Importantes de Button
| Propiedad | Descripción |
|---|---|
android:text | Texto del botón |
android:textColor | Color del texto |
android:textSize | Tamaño del texto |
android:background | Fondo del botón |
android:enabled | Habilita/deshabilita el botón |
android:onClick | Método a ejecutar al hacer click (XML) |
android:drawableLeft | Icono a la izquierda |
android:drawablePadding | Espacio entre icono y texto |
app:cornerRadius | Radio de las esquinas (Material) |
app:strokeColor | Color del borde (Material) |
app:strokeWidth | Grosor del borde (Material) |
app:icon | Icono del botón (Material) |
app:iconGravity | Posición del icono (Material) |
🟩 12. Button con Animación
private void animateButton(Button button) {
// Animación de escala
button.animate()
.scaleX(1.1f)
.scaleY(1.1f)
.setDuration(200)
.withEndAction(() -> {
button.animate()
.scaleX(1.0f)
.scaleY(1.0f)
.setDuration(200)
.start();
})
.start();
}🟩 13. Métodos para Configurar Click Listeners
Método 1: Lambda (Recomendado - Java 8+)
button.setOnClickListener(v -> {
// Tu código aquÃ
});Método 2: Clase Anónima
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Tu código aquÃ
}
});Método 3: Desde XML (onClick attribute)
<Button
android:onClick="myMethod"
android:text="Click Me" />public void myMethod(View view) {
// Tu código aquÃ
}Método 4: Implementar Interface en Activity
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// Tu código aquÃ
}
}▶️ Cómo Ejecutar tu Aplicación
- Abre Android Studio
- Presiona Run para ejecutar el proyecto
- Si no tienes un emulador, crea uno desde AVD Manager
- Verás todos los tipos de botones con diferentes estilos funcionando
🧪 Resultado Final
Tu aplicación mostrará:
- Botones estándar con diferentes estilos
- Material Design Buttons (Filled, Outlined, Text)
- Image Buttons circulares con iconos
- Toggle Button y Switch con estados
- Botones personalizados (gradientes, bordes, redondeados)
- Click Listeners funcionando con diferentes métodos
- Estados visuales (normal, presionado, deshabilitado)
📥 Descargar Proyecto de Ejemplo
Puedes descargar el proyecto completo desde el siguiente enlace:
👉 Descargar
🙌 Gracias por Visitar mi Blog
Si este tutorial te fue útil:
✔️ Compártelo
✔️ Déjame un comentario
✔️ SÃgueme para más contenido sobre Android y programación
¡Estoy aquà para ayudarte!
❓ Preguntas Frecuentes (FAQ)
1. ¿Cuál es la diferencia entre Button y MaterialButton?
MaterialButton es parte de Material Design y ofrece más opciones de personalización como bordes, iconos integrados, esquinas redondeadas y estilos predefinidos más modernos que el Button estándar.
2. ¿Cómo puedo deshabilitar un botón temporalmente?
Usa el método button.setEnabled(false) para deshabilitar y button.setEnabled(true) para habilitar. Los botones deshabilitados no responden a clicks y cambian su apariencia visual automáticamente.
3. ¿Cuál es el mejor método para configurar Click Listeners?
El método Lambda es el más limpio y legible en Java 8+. La clase anónima es útil cuando necesitas compatibilidad con versiones antiguas o lógica más compleja dentro del listener.
4. ¿Puedo agregar múltiples iconos a un botón?
Con Button estándar puedes usar drawableLeft, drawableRight, drawableTop y drawableBottom. Con MaterialButton puedes usar la propiedad app:icon y controlar su posición con app:iconGravity.

No hay comentarios:
Publicar un comentario