移动开发----平板电脑或者小屏幕设备

来源:互联网 发布:radeon pro 580windows 编辑:程序博客网 时间:2024/05/05 06:45
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;    }}

阅读全文
1 0
原创粉丝点击