How to detect the android screen size programmatically ( the 4 standard sizes)?

StackOverflow https://stackoverflow.com/questions/17612048

  •  02-06-2022
  •  | 
  •  

質問

I know there are 4 standard screen sizes for android :

xlarge,large, normal and small 

How to know the running device which screen size has from these 4 sizes ?

役に立ちましたか?

解決

int screenSize = getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK;

switch(screenSize) {
    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();
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top