android - 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()
.
解决方案
值/字符串.xml
<bool name="is_tablet">false</bool>
values/sw900dp/sting.xml
或
values/sw600dp/string.xml
或
values/sw720dp/string.xml
<bool name="is_tablet">true</bool>
检查这个;
boolean isTablet = getResources().getBoolean(R.bool.is_tablet);
如果是“ dimen
”,可以放在dimen中。
推荐阅读
- c# - 为什么同一页面的每个页面加载后内存使用量都会增加
- python - 您可以通过将一行中的所有单元格值设置为“无”来使用 openpyxl 删除 Python 中的行吗?
- react-native - 使用 mapDispatchToProps 将当前状态从一个屏幕传递到另一个屏幕
- python - Python 导入突然失败
- java - 使用 REST API 的后端事务
- github-pages - 如何解决GitHub页面创建过程中“无法检索域的DNS记录”?
- css - 如何修复容器采用 ::after 样式
- graphql - 如何修复“语法错误:预期名称,在 GraphQL 中找到字符串“查询”
- c# - SQL异常判断记录存在的原理是什么?
- html - 在进度条步骤中显示图像