I am working with ImageButtons
but I am not able to create a border when clicking on them. I know that there is another question regarding this topic but after following the answer, I have not been able to make it work.
Currently my code is:
ib_shape_corner.xlm
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="3dp"
android:color="@color/blue1" />
<padding
android:left="3dp"
android:top="3dp"
android:right="3dp"
android:bottom="3dp" />
<corners
android:bottomRightRadius="8dip"
android:bottomLeftRadius="8dip"
android:topRightRadius="8dip"
android:topLeftRadius="8dip" />
</shape>
ib_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/ib_shape_corner" />
<item android:drawable="@android:color/transparent" />
</selector>
main.xml
<ImageButton
android:id="@+id/ib_img"
android:layout_width="160dp"
android:layout_height="100dp"
android:background="@drawable/ib_selector"
android:src="@drawable/ic_img"
android:padding="5dp">
main.java
Here I have tried setting to pressed and to selected my button when clicking on it but it has not worked
ib_img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ib_img.setSelected(true);
ib_img.setPressed(true);
// Do my stuff
}
});
The listener
works since it actually run my code when clicking but the border is not added.