2022-10-22

【Kotlin】偵測 Android 裝置的螢幕尺寸

 
...
...
    
when(this.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK) {
    Configuration.SCREENLAYOUT_SIZE_SMALL -> Toast.makeText(this, "320x426", Toast.LENGTH_LONG).show()
    Configuration.SCREENLAYOUT_SIZE_NORMAL -> Toast.makeText(this, "320x470", Toast.LENGTH_LONG).show()
    Configuration.SCREENLAYOUT_SIZE_LARGE -> Toast.makeText(this, "480x640", Toast.LENGTH_LONG).show()
    Configuration.SCREENLAYOUT_SIZE_XLARGE -> Toast.makeText(this, "720x960", Toast.LENGTH_LONG).show()
    Configuration.SCREENLAYOUT_SIZE_UNDEFINED -> Toast.makeText(this, "undefined", Toast.LENGTH_LONG).show()
    else -> Toast.makeText(this, "I don't know", Toast.LENGTH_LONG).show()
}


...
...
 

手機


平板




沒有留言:

張貼留言