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.
The code below fleshes out the answer above, displaying the screen size as a Toast.
This code below displays the screen density as a Toast.
Copy and paste this code into your
Activity
and when it is executed it willToast
the device's screen size category.Try this function isLayoutSizeAtLeast(int screenSize)
To check small screen, atleast 320x426 dp and above getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL);
To check normal screen, atleast 320x470 dp and above getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL);
To check large screen, atleast 480x640 dp and above getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE);
To check extra large screen, atleast 720x960 dp and above getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE);
Jeff Gilfelt's answer as a static helper method:
You can use the
Configuration.screenLayout
bitmask.Example: