Skip to content

Instantly share code, notes, and snippets.

@ageorg
Created November 19, 2016 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ageorg/1bad1a2b9a6cdbef5c261885ce302ccc to your computer and use it in GitHub Desktop.
Save ageorg/1bad1a2b9a6cdbef5c261885ce302ccc to your computer and use it in GitHub Desktop.
Determin the screen size of an android device
int screenSize = getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK;
switch (screenSize) {
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
Toast.makeText(this, "Extra large screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Toast.makeText(this, "Large screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
Toast.makeText(this, "Normal screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
Toast.makeText(this, "Small screen", Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(this,
"Screen size is neither large, normal or small",
Toast.LENGTH_LONG).show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment