LoginSignup
14
15

More than 5 years have passed since last update.

[Android] コードでタブレット判定する

Last updated at Posted at 2016-02-26

コードを使った方法

調べると色々な方法がでてきますが
googleI/O 2015のアプリの中では以下のようにやってました。

public static boolean isTablet(Context context) {
        return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
}

リソースを使った方法

一応リソースを使った方法も
res/values-sw600dp/bool.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_tablet">true</bool>
</resources>

res/values/bool.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_tablet">false</bool>
</resources>

判定

public static boolean isTablet(Context context) {
        return context.getResources().getBoolean(R.bool.is_tablet);
}
14
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15