> For the complete documentation index, see [llms.txt](https://ricardev.gitbook.io/apuntes-android/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ricardev.gitbook.io/apuntes-android/escribiendo-tu-primera-app/paradigmas-de-diseno/views/pallete-buttons/imagebutton.md).

# ImageButton

{% embed url="<https://developer.android.com/reference/android/widget/ImageButton>" %}
Fuente: developer.android
{% endembed %}

## DEFINICIÓN

Hereda de `ImageView`.

Muestra un botón con una imagen en vez de un texto que puede ser clicado por el usuario.

Por norma general es igual que un `Button` pero con una imagen en vez de texto, por este motivo, el estilo por defecto que se aplica a la clase `Button` tambien se aplica a la clase `ImageButton`.

La imagen que se muestra se define en el archivo de layout XML con el atributo `android:srcCompat` o en código con el método `setImageResource(int)`.

{% code title="activity\_main.xml" %}

```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="30dp"
    android:orientation="vertical">

    <ImageButton
        android:id="@+id/ibtEjemplo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_car"
        android:backgroundTint="@color/purple_200"/>

</LinearLayout>
```

{% endcode %}

{% code title="MainActivity.kt" %}

```kotlin
package com.example.android.appdeejemplo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageButton
import android.widget.Toast

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val bEjemplo = findViewById<ImageButton>(R.id.ibtEjemplo)
        bEjemplo.setOnClickListener {
            Toast.makeText(this, "Botón Pulsado", Toast.LENGTH_SHORT).show()
        }
    }
}
```

{% endcode %}

![](/files/SBRgakANKQO1G8P1JVsN)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ricardev.gitbook.io/apuntes-android/escribiendo-tu-primera-app/paradigmas-de-diseno/views/pallete-buttons/imagebutton.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
