INVISIBLE vs GONE View in Android

Lot of time we have a requirement to hide the view either runtime or from xml. We have seen View.GONE and View.INVISIBLE but very few people knows difference between those two constants.

First we will see what android document says about it.


This view is invisible, but it still takes up space for layout purposes.


This view is invisible, and it doesn’t take any space for layout purposes.

Continue Reading

Disable future dates from DatePickerDialog in Android

As we already know DatePickerDialog will be used to allow user to select date. It is useful when user wants to select Date of Birth or Start Date or End Date etc.

Here is the small code snippet of creating DatePickerDialog.

Continue Reading

getResources().getColor() is deprecated

As we already know getResources().getColor() is deprecated since API level 23 from the official document

So what is the alternative of getColor()?

from API level 23, getColor is added in ContextCompat.

So just call

from official document of ContextCompat.getColor()

Returns a color associated with a particular resource ID

Starting in M, the returned color will be styled for the specified Context’s theme.

Android DataBinding With Fragment

As we already know how to use DataBinding with Activity from Working with Data Binding Android article, but here we will see how to use DataBinding with fragment.

To bind a view of fragment we need to use onCreateView() . Here is a code snippet of fragment onCreateView()

Disable Landscape Mode In Android Application

As we have seen it creates so many problems when you rotate your device or when orientation is changed from portrait to landscape and vice-versa. However, there is a code to avoid that, but I have seen so many developers just disables landscape mode so that your application will be in portrait mode only all the time.

Whether rotation of device is on or off doesn’t matter, your application will be in portrait mode only.

To do that, you just need to add android:screenOrientation=”portrait” to an activity you have mentioned in the AndroidManifest.xml file.