0

i want to add a border to my imagebutton when i press it.

Now i have this code:

 <ImageButton
            android:id="@+id/ficha"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/textElementos"
            android:layout_marginStart="20px"
            android:background="@drawable/bordebotonespaleta"
            android:onClick="pintarFicha"
            android:src="@drawable/fichapaleta" />

And this is my drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true"
        android:drawable="@drawable/botonpressed"/>
    <item android:drawable="@android:color/black" /> <!-- default -->
</selector>

This is buttonpressed:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="2dp" />
    <solid android:color="#e6ff0000" />
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />
    <size
        android:width="100dp"
        android:height="35dp" />
    <stroke
        android:width="10dp"
        android:color="#1DE9B6" />
</shape>

This code does not work for me. I dont know why.

I use this like reference How to change the color of the color button when pressed in Android? but as i say, this not work for me.

garciam202
  • 591
  • 2
  • 7
  • 17
  • you can change the border color, when the button is click programmatically. Have a look at this [answer](https://stackoverflow.com/a/23175014/4056108) – chirag90 Sep 12 '17 at 14:40
  • what do you mean by "it doesn't work"? does it switch the state? – nikis Sep 12 '17 at 14:41
  • i want to say that the border when i press the button does not appear, but the state change to isPressed = true – garciam202 Sep 12 '17 at 15:01
  • try to remove the `size` element on your drawable, because it is background, its size should be dynamic, depending on the content. – nikis Sep 12 '17 at 15:03

0 Answers0