Remove the white background from my image png

1

I am working on an application in Android Studio and I have read in several threads that to remove the background in my buttonimage I have to put in its Android properties: Background="null" .

Indeed the background is removed and there is a transparent image that is what I'm looking for, but I miss the following error:

  

Error: (14, 28) String types not allowed (at 'background' with value   '').

Can someone tell me how to solve it?

    
asked by DPlay97 02.10.2017 в 10:40
source

3 answers

1

Try the following in the corresponding activity:

ImageView image = (ImageView) findViewById(R.id.id_de_tu_imageView);

image.setBackgroundDrawable(null);

or as the partner "Pikoh" android:background="@null" said in the ImageView of your xml.

    
answered by 02.10.2017 в 11:26
0

Use the symbol '@' in front of null when establishing the reference; in this way: android:background="@null" , you can also use android:background="@android:color/transparent" .

Your error is because you are assigning a string to the background property when it needs a reference to a drawable, in this case @null represents the absence of this.

When you assign the @null reference to the background property, any element that is behind it will be displayed, in your specific case, the background and edges of the button will disappear.

    
answered by 02.10.2017 в 14:36
0

If you set the android: background , it is strictly necessary to define the resource, it can be color, image or a drawable .xml, the color can even have transparency

android:background="@???/???"

For the error message I gather that you are loading an empty value:

android:background=""

or the resource refers to an empty value, for example:

android:background="@color/mi_color"

where the value has not been specified:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="mi_color"></color> 
</resources>
  

How to remove the white background from my ImageButton '?

You can programmatically assign a null value to the background:

imageButton.setBackgroundDrawable(null);

or by defining the value in the layout:

android:background="@null"
    
answered by 02.10.2017 в 18:55