首页 > 解决方案 > How to detect tablet or smartphone using tablet()?

问题描述

I am stuck while detecting tablet or smartphone. I have the application that should work on tablet as well as phone. I am not able to conclude how to code to detect the device. I have created the layouts for both tablet and phone.

I want to use is Tablet().

标签: android

解决方案


值/字符串.xml

<bool name="is_tablet">false</bool>

values/sw900dp/sting.xmlvalues/sw600dp/string.xmlvalues/sw720dp/string.xml

<bool name="is_tablet">true</bool>

检查这个;

 boolean isTablet = getResources().getBoolean(R.bool.is_tablet);

如果是“ dimen”,可以放在dimen中。


推荐阅读