Ben
Ben

Reputation: 1849

Disable button click effect in xml

I created a simple ImageButton in my app and im using and image in it.

I had like that when I click the button that it wont show that it was clicked (not sure how it is called but when the button changes color).

My button looks as follows:

enter image description here

and when I click it becomes:

enter image description here

<ImageButton
    android:id="@+id/returnButton"
    style="?android:borderlessButtonStyle"
    android:layout_width="40dp"
    android:layout_height="0dp"
    android:layout_marginStart="16dp"
    android:src="@drawable/ic_rarrow"
    app:layout_constraintBottom_toBottomOf="@+id/tv_Username"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/tv_Username">
</ImageButton>

I want to remove this gray background even when clicked because it shows boundaries that I wish to hide.

Thank you

Upvotes: 1

Views: 3976

Answers (4)

Simin Ghasemi
Simin Ghasemi

Reputation: 91

Within your code, you can use this:

button.setBackgroundColor(Color.TRANSPARENT);

Upvotes: 0

Zain
Zain

Reputation: 40898

You can apply a transparent background to the ImageButton

android:background="@android:color/transparent"

Upvotes: 2

Karan Dhillon
Karan Dhillon

Reputation: 1234

Apply a background to the Button:

android:background="@android:color/white"

Upvotes: 0

Fred
Fred

Reputation: 137

You can solve the problem by adding one line of code.

android:background="@null"

Hoping it will be helped

Upvotes: 1

Related Questions