Is there any way to determine the category of screen size of the current device, such as small, normal, large, xlarge?
Not the density, but the screen size.
Is there any way to determine the category of screen size of the current device, such as small, normal, large, xlarge?
Not the density, but the screen size.
Thanks for the answers above, that helped me a lot :-) But for those (like me) forced to still support Android 1.5 we can use java reflection for backward compatible:
Need to check for xlarge screens & x..high densities? This is the altered code from the chosen answer.
In 2018, if you need Jeff's answer in Kotlin, here it is:
Couldn't you do this using a string resource and enums? You can define a string resource that had the name of the screen size, such as SMALL, MEDIUM, or LARGE. Then you could use the value of the string resource to create an instance of the enum.
Define an Enum in your code for the different screen sizes you care about.
Define a string resource, say screensize, whose value will be either SMALL, MEDIUM, or LARGE.
screensize
in a string resource in each dimension you care about.For example,
<string name="screensize">MEDIUM</string>
would go in values-sw600dp/strings.xml and values-medium/strings.xml and<string name="screensize">LARGE</string>
would go in sw720dp/strings.xml and values-large/strings.xml.ScreenSize size = ScreenSize.valueOf(getReources().getString(R.string.screensize);
If you want to easily know the screen density and size of an Android device, you can use this free app (no permission required): https://market.android.com/details?id=com.jotabout.screeninfo
Here is a Xamarin.Android version of Tom McFarlin's answer