public class DeviceUtils {
private static Boolean mIsTablet;
private static Boolean mIsSmallScreen;
//如果设备是平板电脑
public static boolean isTablet(Context context) {
if (mIsTablet == null) {
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
mIsTablet = (xlarge || large);
}
return mIsTablet;
}
//如果设备是小屏幕
public static boolean isSmallScreen(Context context) {
if(mIsSmallScreen == null) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
mIsSmallScreen = size.x <= 768;
}
return mIsSmallScreen;
}
}
移动开发----平板电脑或者小屏幕设备
最新推荐文章于 2024-04-09 15:44:54 发布