82

I found the following attribute in one xml layout:

android:background="@null"

What is the meaning of @null? What is the difference between specifying background="@null" and omitting background attribute?

Maggie
  • 7,823
  • 7
  • 45
  • 66
  • 3
    Here is a nice explanation for you query. [Android Developer Blogspot](http://android-developers.blogspot.com/2009/03/window-backgrounds-ui-speed.html) [How to have a transparent ImageButton: Android](http://stackoverflow.com/questions/3402787/how-to-have-a-transparent-imagebutton-android) These two links will surely clear your query. – Lalit Poptani Sep 29 '11 at 08:58
  • Reading the first link requires patience but it was worth it. DO READ IT. – eRaisedToX Mar 02 '17 at 10:54

2 Answers2

81

If I remember correctly, omitting the background attribute sets a default background. However, explicitly setting background to "@null" removes the background, causing whatever is below the element to be shown. In particular, if you for instance set the background of a Button to null, the border of the button will also be gone (and the button effectively will not really look like a button at all).

Dino
  • 1,576
  • 12
  • 12
7

What i have observed if i do android:background="@null"or android:background="@android:color/transparent" both have same effect, they just remove the background of the view, so you will see the background colour of the view which is beneath this view.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
  • 1
    For me @android:color/transparent is working ok, the other one: android:background="@null" is throwing an error, I'm using a constraint layout as a container. Thanks! – dicarlomagnus May 01 '19 at 21:29
  • Ripple shape also different when using @null or transport. – Daniel Jul 24 '20 at 14:56