Home » Android » android – How to remove the border behind the button?

android – How to remove the border behind the button?

Posted by: admin April 23, 2020 Leave a comment

Questions:

There is a grey border behind my app button, how can I remove this?

I defined the ImageButton like this:

<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="startPhotoLibAction"
    android:src="@drawable/library_blau_2" />
How to&Answers:

You have to use style="?android:attr/borderlessButtonStyle":

<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="startPhotoLibAction"
    android:src="@drawable/library_blau_2"
    style="?android:attr/borderlessButtonStyle"/>

Answer:

try this :

<ImageButton
        android:id="@+id/btn_photo_lib"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="startPhotoLibAction"
        android:background="@android:color/transparent"
        android:src="@drawable/library_blau_2" />

Answer:

Simple and easy way is

android:background="?android:attr/selectableItemBackground"

Answer:

I found this works just fine:

android:background=”@null”

Answer:

Just change the background of your imageview to transparent as below:

<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent" <----- Set background.
    android:onClick="startPhotoLibAction"
    android:src="@drawable/library_blau_2" />

OR You can only set the background then you don’t need to apply the transparent color.

<ImageButton
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/download" <--- set only the background
    android:onClick="startPhotoLibAction"
 />